Reputation: 4813
The following code
#include <iostream>
template<typename T>
class Abstract
{
public:
virtual ~Abstract()
{}
virtual void func(const T ¶m) const = 0;
};
class Concrete : public Abstract<int*>
{
public:
virtual void func(const int *¶m) const override // watch out!
{}
};
int main()
{
Concrete c;
}
produces the following compile error at the line marked with the comment:
error C3668: 'Concrete::func' : method with override specifier 'override' did not override any base class methods
If I remove the override
, this error will be shown:
error C2259: 'Concrete' : cannot instantiate abstract class
How to derive from Abstract<int*>
?
Upvotes: 3
Views: 90
Reputation: 8805
You want this:
virtual void func(int * const ¶m) const override // watch out!
Upvotes: 1
Reputation: 4813
Declare Concrete
like this:
class Concrete : public Abstract<int*>
{
public:
virtual void func(int * const ¶m) const override
{}
};
The question is: Which part of the parameter of Abstract<int*>::f()
is const
?
The answer: Since T
is const
and T
in Abstract<int*>
is a pointer (to an int
), it is the pointer that is const
- not the int
.
Upvotes: 4