Quote:Original post by Skeleton_V@TWell... not necessarily. In truth you can reuse message classes but assign different typecodes - e.g. if you have a set of messages which all just attach an entity ID as their data, then you could have a MessageWithEntityID class that you use for all those typecodes.
superpig,
Taking a deeper look at your (original) solution, a question is raised: The DoProcessMessage () takes an object of type derived from Base_Msg, so for every message types I have the same amount of respective classes, is that ?.
Quote:All these message classes need to be declared in a commonly-separated header, which is likely to have the same problem as the double-dispatching solution.In the original implementation I cited, no. The implementation of a concrete message handler will need to import definitions of the message classes that it actually uses so that it can perform the typecast; it doesn't need to import message classes that it's not going to try and cast to.
In my second implementation, the base message handler needs to be aware of all the message classes, though it doesn't actually need to have them fully declared - forward declaration suffices. Without them, it can't declare all the base overrides of HandleMessage(), but because HandleMessage doesn't try to use the type at all it doesn't need to know about the actual definition of the type. Once you start writing derived message handlers that actually inspect/use the message data, then you need to import headers for the classes that you use.