c++ - 错误 : no match for 'operator==' (operand types are 'Seat' and 'std::string {aka std::basic_string<char>}' )

标签 c++

我浏览了过去的问题,找不到适合我的答案。所以,我一直在这个方法中遇到错误。非常感谢您的帮助。

错误是:

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/

相关文章:

c++ - 标准中override和noexcept的顺序

c++ - std::unordered_map:多线程插入?

c++ - C++ 中的基本单例对象

c++ - C++如何将纸牌游戏中的纸牌相加?

c++ - 如何计算 C++ 程序中函数的 GFLOP?

python - 带有类方法的 Cython 回调

c++ - 如何声明一个静态变量但不定义它

c++ - 了解后缀表达式评估代码

c++ - 使用空指针参数和不可能的后置条件构造标准异常

c++ - SetLayeredWindowAttributes 不适用于 Windows 7