I'm overloading the packet class and running into a bit of an issue.
I have an Actor class that many classes will inherit from; e.g. player class and enemy class.
I would like to extract a generic Actor class from a packet.
packet >> actorObject;However, if the object is a derived class, then I believe it will be truncated (or crash?) if it is assigned to a super class object.
What I would like to do is get a pointer to what is to be extracted, and do a dynamic cast to check the type of object;
Actor* temporary = &(packet >> ? ? ? ? )
derived* casted = dynamic_cast<derived>(temporary)
if(derived != nullptr){
//do stuff
}The problem is, I'm not sure how I can do this without knowing the type of the object before extracting it from the packet. I could solve this problem by extracting a flag value first, but then I would need if statments for every type of object.
Does anyone have any input?
Thanks.