gpt4 book ai didi

c++ - 运算符重载中没有运算符 '==' 匹配

转载 作者:行者123 更新时间:2023-11-30 03:25:12 25 4
gpt4 key购买 nike

<分区>

我正在研究“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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com