samedi 29 avril 2017

overriding the template base method in derived class?

Suppose I have a base class as below:

template <typename T>
class Base {
// implementation
void do_something() { // ...} ;
};

then, I create a Derived class as below, and override the do_something() method:

template <typename T>
class Derived : public Base<T> {
    // implementation
    void do_something() { // ...} ;
};

I know virtualization does not work in class templates, but I do want to store a bunch of derived classes and base classes into a vector, (I do not want to use type erasure, or polymorphism),

my question is, given that static_cast of Derived class to base class gives me the do_something of based class, Is there any way that I can store them as base classes while each has their implementation of do_something() class ?!!!

Thanks

Aucun commentaire:

Enregistrer un commentaire