You could write simpler
IIcon& retval = *obj;
Вопрос
I have a quick question regarding Base->Derived class relationships and casting. Like the title says, I need to cast a pointer to a derived class to a reference to a parent class. Currently, I have this code:
IIcon& retval = static_cast<IIcon&>(*obj)
, where obj is a AtlasTexture*
object, which is a derived class of IIcon
.
I am still a little foggy on the many different types of casts in C++, and was wondering if this would work, and if there was a more efficient or safe way to do this same thing.
Thanks.
Решение
You could write simpler
IIcon& retval = *obj;