我在重写基类运算符==时遇到问题。这是代码。
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
class IClient {
virtual const std::vector<T>& getID() = 0;
virtual bool isEqual(const std::vector<T>& anotherID) = 0;
virtual bool operator==(const IClient& anotherClient) = 0;
};
class SeviceClient : public IClient<int8_t> {
const std::vector<int8_t> ID;
public:
SeviceClient(const std::vector<int8_t>& ID) : ID(std::move(ID)) {}
SeviceClient(const std::vector<int8_t>&& ID) : ID(std::move(ID)) {}
const std::vector<int8_t>& getID() override {
return ID;
}
bool isEqual(const std::vector<int8_t>& anotherID) override {
return true;
}
bool operator==(const SeviceClient& anotherClient) override {
return true;
}
};
它提示说
error: 'bool SeviceClient::operator==(const SeviceClient&)' marked 'override', but does not override
当我将函数转换为时,编译器看起来很高兴
bool operator==(const IClient<int8_t>& anotherClient) override {}
这是问题的解决方案还是我在这里遗漏了一些东西?
谢谢
最佳答案
SeviceClient 和 IClient 是不同的类型。 因此, bool SeviceClient::operator==(const SeviceClient&) 没有基本声明。
关于c++ - 运算符 == 标记为 'override' ,但不覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68225394/