   pass-by-reference and vars on the stack
  Hi all,If I have the following:   void ClassA::SomeFunc(){   SomeClass var1;   ClassBInstance->AnotherFunc(var1);}void ClassB::AnotherFunc(const SomeClass& foo){   MyVector.push_back(foo);}where MyVector is a vector of SomeClass in ClassB and ClassBInstance is an instance of ClassB in ClassA, is that perfectly legal and valid?  I'm putting a reference to a class which is created on the stack into the vector.  I understand that the way to think about references is as an alias to a variable.  Well in this case the variable was created on the stack.Actually when I call push_back a new SomeClass is constructed right?  So I'll have a copy.. I think that answers my question.  But what if I had a vector of references, or is that not allowed?cheerssam[edited by - izzo on February 16, 2004 12:03:57 AM][edited by - izzo on February 16, 2004 12:34:02 AM]
  You can't have a vector of references.If your vector is vector<SomeClass> MyVectorthen when you push_back(), it'll make a copy.   [Edit]: code tag makes the < and > disappear.Kami no Itte ga ore ni zettai naru!   [edited by - tangentz on February 16, 2004 12:38:16 AM];  If you want a vector of references, you have to use pointers:vector<ClassName *> v;v.push_back(&object);Then, the vector makes a copy of the address of the object instead of a copy of the object itself.  You can modify the object via either pointer, and the results will be visible from both. ;  Ahh thanks guys.  I should have known that, it''s quite obvious..   I''m well-versed in the use of pointers.  It was just some subtle details about references and (mostly) implicit instantiation (is that the right term or does that only refer to templates?) that I needed to clear up.Thanks!sam;  Also, you have to keep in mind that a type must be assignable, default constructable, and copy constructable in order to be used reliably in standard containers such as vector, which is one of the reasons why you can''t store references  daerid | Legends | Garage Games | Spirit | Hapy | Boost | Python | Google"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool 