I’m working on a project where I have 2 classes: Room and EventRoom
EventRoom inherits from Room and have a few more members.
In my code I do this(tmpPtr is a Room-pointer):
if(eventRoom)
tmpPtr = dynamic_cast<EventRoom*>(tmpPtr);
and later when I try this:
if(line == "false;")
tmpPtr->setComplete(false);
I get compilation errors. setComplete is a member of EventRoom
Short version: I want to create objects of type Room, and in some cases EventRoom. The code currently works for Room only, but 90% of the code would be identical for EventRoom. Any way of using the same code? (with dynamic_cast or something similiar)
You need
tmpPtrto be anEventRootpointer.You can only call
Roompublic methods on aRoompointer. You cannot callEventRoom-only methods.