View Full Version : call-by-ref in function within function (C++)

04-27-2004, 06:42 PM
void somefunction(map<char,vector<node*> >&);
void subfunction(map<char,vector<node*> >&, queue<int>&);

void main(){
map<char,vector<node*> > m1;

void somefunction(map<char,vector<node*> >& m){
queue<int> Q;

void subfunction(map<char,vector<node*> >& m, queue<int>& q){
//I = m.begin();
node *ptr = I->second[q.front()];
cout << ptr->data << endl;

The error is in the subfunction. Assuming the map is

initialized with data, the "ptr->data" does not work. When I

debug, it says ptr is a "Bad Ptr". Does this have anything to

do with calling by reference within a function? It works fine when I replace "q.front()" with an integer. Thanks.

05-03-2004, 08:39 AM
Your "I" is obviously meant to be an iterator, declare it as such. Use (*I).second instead of I->second. Then there is the apparent problem that Q will be empty in your code snippet, so q.front() will return an invalid value.