简体   繁体   中英

error: no match for 'operator==' (operand types are 'Seat' and 'std::string {aka std::basic_string<char>}')

I went through past questions, and could not find an answer specific to mine. So, I keep getting at an error in this method. Would really appreciate your help.

The error is:

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;
}

It seems quite self-explanatory:

no match for ' operator== ' (operand types are ' Seat ' and ' std::string {aka std::basic_string} ')

No implementation of operator == exists which accepts a left hand side of Seat type and a right hand side of std::string .

Which makes sense since you are trying to compare apple and oranges, if you want to make the compiler compare them then you'll have to tell it how to do, eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM