class Message {};
class BuildSandCastle : public Message {};
class DigHole : public Message {};
Given an arbitrary Message*
object, how can I call a function of the same name doMessage()
without resorting to switch logic or making a MessageHandler class that has one 'do' function for every message name?
EDIT: for example:
class Sandbox
{
public:
void play(Message* m)
{
// call doBuildSandCastle
// or doDigHole based on m's type
}
void doBuildSandCastle();
void doDigHole();
};
Sorry I wasn't clear before.
EDIT:
can someone just delete this train wreck of a question? I really don't want all these highschool lessons in polymorphism.