Domanda

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.

È stato utile?

Soluzione

You could write simpler

IIcon& retval = *obj;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top