"foggy" <fo***@turboweb.com> wrote in message
news:AA*******************@bgtnsc05-news.ops.worldnet.att.net...
Derived1 and Derived2 are derived from BaseClass:
list<BaseClass&> lst;
Derived1 d1;
Derived2 d2;
lst.push_back(d1);
lst.push_back(d2);
Can a list be created like above so that d1, d2... objects can be
navigated to?
No, use pointers instead.
I read somewhere "A list container should not contain a list of references
since they are not assignable." What does this mean? Thanks!
Err, exactly what it says (except I would say 'cannot' not 'should not').
Lists make some assumptions on the objects they contain, one of which is
that the objects themselves can be assigned. References cannot be assigned
int a = 1;
int b = 2;
int& r = a;
r = b;
r = b does not assign to the reference, it assigns the value of b to a, r
still refers to a.
john