I have a piece of code, that consists of an engine, a queue of pointers of requests processed by the engine, and a set of different types of requests, all of them classes - one 'most general' and a lot of variants.
Now, one of these request types requires a special handling.
class GenericRequest {};
class SpecificRequest1 : public GenericRequest {};
class SpecificRequest2 : public GenericRequest {};
class VerySpecialRequest : public GenericRequest {};
The queue just contains pointers (of type GenericRequest*
) to instances. GenericRequest
is instantiated too - instances of it appear in the queue too.
I need the engine to single out VerySpecialRequest
and perform extra operations as it appears.
If I understood the answer involving inheritance in How to identify failed casts using dynamic_cast operator?, in my case using:
VerySpecialRequest* result = dynamic_cast<VerySpecialRequest*>( queue_entry );
if(result != NULL) { /* process the special entry */ }
will catch instances of GenericRequest
on top VerySpecialRequest
, only filtering off SpecificRequest1
and SpecificRequest2
.
How can I go about identifying this specific child?