我浏览了过去的问题,找不到适合我的答案。所以,我一直在这个方法中遇到错误。非常感谢您的帮助。
错误是:
error: no match for 'operator==' (operand types are 'Seat' and 'std::string {aka std::basic_string}')
void SeatsCreateReservation(vector<Seat>& seats) {
string account_ID;
unsigned int seatNum = 0;
Seat seat;
cout << "Enter username: ";
cin >> account_ID;
for (seatNum = 0; seatNum < seats.size(); seatNum++) {
if (seats.at(seatNum) == account_ID) {
cout << "Seat number too large." << endl;
break;
}
}
seat.Reserve(account_ID);
seats.at(seatNum) = seat;
cout << "Completed." << endl;
return;
}
最佳答案
这似乎是不言自明的:
no match for '
operator==
' (operand types are 'Seat
' and 'std::string {aka std::basic_string}
')
不存在接受 Seat
类型左侧和 std::string
右侧的运算符 ==
的实现.
这是有道理的,因为你正在尝试比较苹果和橘子,如果你想让编译器比较它们,那么你必须告诉它该怎么做,例如:
bool operator==(const Seat& seat, const std::string&string) {
...
}
关于c++ - 错误 : no match for 'operator==' (operand types are 'Seat' and 'std::string {aka std::basic_string<char>}' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40814830/