문제

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top