运算符重载中没有操作员'=='匹配项
No operator '==' matches in operator overloading
我正在研究"Roman to int"算法,我的代码如下。我收到一个错误:
no operator "==" matches these operands -- operand types are: char == const Solution::symbol.
有人可以帮我修复代码吗?
// solution.h
#include <string>
using namespace std;
class Solution {
private:
struct symbol {
char upperCase;
char lowerCase;
bool operator ==(char ch) {
return ch == upperCase || ch == lowerCase;
};
};
static constexpr symbol one {'I', 'i'};
static constexpr symbol five {'V', 'v'};
static constexpr symbol ten {'X', 'x'};
static constexpr symbol fifty {'L', 'l'};
static constexpr symbol hundred {'C', 'c'};
static constexpr symbol fiveHundred {'D', 'd'};
static constexpr symbol thousand {'M', 'm'};
public:
bool romanToInt() {
char ch = 'I';
ch == one; // ERROR: no operator "==" matches these operands -- operand types a re: char == const Solution::symbol
one == ch; // ERROR: no operator "==" matches these operands -- operand types a re: const Solution::symbol == char
};
};
// main.cpp
#include <iostream>
#include "../Header Files/solution.h"
using namespace std;
int main() {
Solution solution;
solution.romanToInt();
return 0;
}
至少声明运算符
bool operator ==(char ch) const {
return ch == upperCase || ch == lowerCase;
};
和使用
return one == ch;
相关文章:
- 继承函数的重载解析
- 友谊和操作员+=重载
- C++重载>>和<<操作员
- 运算符重载中没有操作员'=='匹配项
- 更改重载操作员的签名
- C []索引操作员重载作为登录器和突变器
- 使用多个操作员与操作员重载会产生奇怪的错误
- 操作员重载=修改原始对象
- 为什么最后一个SR5对象不用重载的新操作员占据内存
- 如何使用此独特的操作员重载功能
- 操作员重载内部调用转换
- 重载<<操作员打印矢量内容
- 在C++重载cout ostream操作员
- 为什么以及如何重载操作员<<进行打印
- 插入运算符重载有什么问题?(<<操作员)
- 操作员在不同命名空间中的不明确重载
- c++重载的操作员工作
- "&"在操作员重载中意味着什么
- 对具有重载操作员>的类型进行就地销毁
- C++操作员重载两次