簡體   English   中英

錯誤:“ operator ==”不匹配(操作數類型為“ Seat”和“ std :: string {aka std :: basic_string <char> }&#39;)

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

我經歷了過去的問題,找不到適合我的答案。 因此,我一直在這種方法中出錯。 非常感謝您的幫助。

錯誤是:

錯誤:“ 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;
}

似乎很不言而喻:

沒有與' operator== '匹配的內容(操作數類型為' Seat '和' std::string {aka std::basic_string} ')

不存在運算符==實現,該實現不能接受Seat類型的左側和std::string的右側。

這是有道理的,因為您要嘗試比較蘋果和桔子,如果要使編譯器比較它們,則必須告訴它如何做,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM