A
Anonymous
I implementing the 'virtual constructor' idiom, I have a retrieve()
method on an interface, which retrieves an object from storage.
I am using this line to cast "up":
MyObject::retrieve()
{
Base * base = Create(object_id) ;
*this = *dynamic_cast<MyObject*>(base) ; //<- this line
...
}
Notes:
i). MyObject derives from Base
ii). Create is a virtual constructor which returns ptr to objects
derived from Base
method on an interface, which retrieves an object from storage.
I am using this line to cast "up":
MyObject::retrieve()
{
Base * base = Create(object_id) ;
*this = *dynamic_cast<MyObject*>(base) ; //<- this line
...
}
Notes:
i). MyObject derives from Base
ii). Create is a virtual constructor which returns ptr to objects
derived from Base