I am writing a piece of software, extensively using miscellanious data
structures : STL lists, vectors etc. The problem is the following:
I have objects of class MyObject, derived from BaseObjectClass.
I have a data container - DataContainer - holding custom created smart
pointers (template class RefPtr<>) to base class (BaseObjectClass).
What I need is to get a reference to object inside the list and set a couple
of properties on it.
I do the following:
MyObject& objRef = *dynamic_cast<MyObject*>((*iterator).GetAddress());
- iterator - is the DataContainer iterator , operator * of it returns
- GetAddress() method returns "bare" pointer to BaseObjectClass from
- I dynamically cast it to MyObject* type and dereference it to initialize
objRef with its value
- SetPropertyOne(true) is trying to set object's property, hoping that this
property will actually be set in the object, stored in the container
But, when I later iterate thru this list and retrieve PropertyOne, it is not
If I use pointers instead of references, everything works OK :
MyObject* objPtr = dynamic_cast<MyObject*>((*iterator).GetAddress());
Please, explain me this behaviour. I am using Visual C++ 6.0, SP3 on Win2K.
Thanx in advance,