错误:'operator =='不匹配(操作数类型为'Seat'和'std :: string {aka std :: basic_string <char>}')

时间:2016-11-26 04:10:50

标签: c++

我经历了过去的问题,找不到我的具体答案。所以,我一直在这个方法中出错。真的很感谢你的帮助。

错误是:

  

错误:'operator =='不匹配(操作数类型为'Seat'和'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;
}

1 个答案:

答案 0 :(得分:1)

这似乎很不言自明:

  

不匹配&#39; operator==&#39; (操作数类型是&#39; Seat&#39;和&#39; std::string {aka std::basic_string}&#39;)

不存在操作符==的实现,它接受Seat类型的左侧和std::string的右侧。

这是有道理的,因为你试图比较苹果和橘子,如果你想让编译器比较它们,那么你必须告诉它怎么做,例如:

bool operator==(const Seat& seat, const std::string&string) {
  ...
}