a queue of references

Aug 18, 2010 at 8:25pm
Assuming I have a stl Queue like this

MyClass
queue<MyClass&>

I used queue<MyClass*> before, and I am wondering whether it is possible to use
queue<MyClass&>

And it seems I have issues on the call of MyClass c = queue.front();

Thanks


Aug 18, 2010 at 8:50pm
you can't store references, references are just a way of passing data into a function. Pointers ftw. If you have a list of pointers to MyClass objects, you cant do

 
MyClass c = queue.front();


as c is an instance of the MyClass object, but queue.front() returns a pointer to a MyClass object.

 
MyClass * c = queue.front();


will work, and gives you a pointer, c, to the first object in the list.
Topic archived. No new replies allowed.