Can I override a method of a class template if it doesn't use the template parameter inside?

153 views Asked by At

I have the following code:

template <typename T>
class A {
public:
    virtual void func() {
        // Things that don't use T parameter.
    }
};

class B : public A<int> {
public:
    void func() {
        A<int>::func();
        // Working...
    }
};

Basically, I want to override a virtual function defined in a class template from inside a class that inherits from a specialized version of such template (A).

Does this work in C++? Is it good practice? Also, is it ok to call the overridden method as I did in the overriding one? (please, note that, for compatibility with the toolchain I'm using, this is C++98)

Thank you.

0

There are 0 answers