4
votes

I'm trying to do have Derived derive from Base:

class Base
{
public:
    Base() {};
};

template <class T>
class Derived : public Base
{
public:
    Derived::Derived()
    {

    }
};

This gives me the following error:

error C3254: 'Derived': class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration

note: see reference to class template instantiation 'Derived' being compiled

error C3244: 'Derived::Derived(void)': this method was introduced by 'Unknown>' not by 'Base'

I'm totally new to templates, what simple steps am I missing? This seems like a pretty basic thing.

1
you get similar error for this code as you would get without the template, even without the inheritance. Btw I am a bit puzzled by the first part of the error message, is this really the code that procudes that error message? - 463035818_is_not_a_number
yep. authentic error from the exact code - Jeffrey
which compiler? Dont get me wrong, I am curious, not complaining ;) - 463035818_is_not_a_number
@formerlyknownas_463035818 VS PRO 2017 15.9.11 - Jeffrey
funny how a simple typo can lead to such a confusing error message. fwiw gccs output is probably a bit more helpful - 463035818_is_not_a_number

1 Answers

7
votes

You need to omit the "Derived::" prefix. You would only use it to refer to a symbol that was inherited, or injected into the namespace of the class Derived. So the only prefix that makes sense is "Base::" here. It has nothing to do with templates.

class Base
{
public:
    Base() {};
};

template <class T>
class Derived : public Base
{
public:
    Derived() {}
};

See a working Live Demo.