I think you will not ask the right question.
To do what you ask, you need to add the following:
template<typename T> class helper : public main_resource_handler { public: virtual resource* create_resource() { return new T; } virtual void do_some(resource* st) { do_some_specific(static_cast<T*>(st)); } private: virtual void do_some_specific(T* st) = 0; };
And change this:
class specific_resource_handler : public helper<specific_resource> { private: virtual void do_some_specific(T* st) { ... } }
static_cast is safe if you can guarantee that you will always call do_some in the right type of handler. But if you already know that this is the correct type of handler, then there is no need to make a call to the base class method. Therefore, presumably, you want to get some resource , not knowing its exact type, and pass it to the appropriate handler. This is harder ...
source share