Reputation: 539
Say I have a template, abstract class:
template <class T>
class MyClass {
public:
virtual bool foo(const T a, const T b) = 0;
}
And another class that wants to inherit, while getting rid of the template:
class MyInheritor : public MyClass<int *> {
public:
bool foo(const int* a, const int* b) { /* stuff */ }
}
The above doesn't let me instantiate MyInheritor, saying it's an abstract class. How can I override the pure virtual method?
Upvotes: 2
Views: 76
Reputation: 3530
Because you are not overriding anything here: the const is applied to the int and not to the pointer to int.
Here is the fixed version you probably want:
class MyInheritorFixed : public MyClass<int *> {
bool foo(int* const a, int* const b) override { return true; }
};
Upvotes: 4