c ++错误“用'override'声明的成员函数未覆盖基类成员”

时间:2019-08-13 17:23:41

标签: c++

我正在学习/测试虚拟功能。以下是我的测试代码,但出现以下错误,无法弄清原因:

“用” override“声明的成员函数不会覆盖基类成员 bool is_satified(Product * item)覆盖{返回item-> color == color;}“

在规范中,我已经将“ is_satisfied”定义为虚拟的。有人可以指出这里有什么问题吗?谢谢!

#include<vector>
#include<iostream>

using namespace std;

enum class Color {red, green, blue};
enum class Size {small, medium, large};

struct Product{
    string name;
    Color color;
    Size size;
};

template <typename T> struct Specification{
    virtual bool is_satisfied(T* item) = 0;
};

struct ColorSpecification: Specification<Product>{
    Color color;
    explicit ColorSpecification(const Color color): color{color} {}
    bool is_satified(Product* item) override{return item->color == color;}
};

int main(){
ColorSpecification green(Color::green);
}

1 个答案:

答案 0 :(得分:8)

有一个错字:

is_satisfied

vs

is_satified

btw using namespace std被认为是不良做法。