2017-10-08 77 views
0
In member function ‘void reviewData::showMaxReviews() const’: 
reviewData.cpp:130:46: error: no matching function for call to 
‘avlTree<std::basic_string<char> >::Findmax(std::string&, double&, unsigned int&) const’ 
purchase.Findmax(name, points, counter); 
reviewData.cpp:130:46: note: candidates are: 
In file included from reviewData.h:6:0, 
      from reviewData.cpp:5: 
avlTree.h:132:7: note: bool avlTree<myType>::Findmax(std::string&, double&, unsigned int&) [with myType = std::basic_string<char>; 
std::string = std::basic_string<char>] <near match> 
bool avlTree<myType>::Findmax(string & name, double & points, unsigned int & count) 

bool avlTree<myType>::Findmax(string &name, double &points, unsigned int &count) 

// This is how product is declared in reviewdata.h 
avlTree<string> purchase; 

void reviewData::showMaxReviews() const 
     string name; 
     double points = 0; 
     unsigned int counter = 0; 
     bool cool; 
     purchase.Findmax(name, points, counter); 

我很難找出究竟是什麼問題,因爲我認爲我傳遞了正確的參數,但我仍然無法編譯。我懷疑這與通過引用有關,但我不確定。沒有匹配的函數調用

回答

0

showMaxReviews函數被標記爲const,這意味着它不能修改reviewData類的任何成員變量。這意味着它不能調用函數this或成員對象,而不是const

findMaxReview功能是不是標記爲const,因此它不能被調用。正如您看到的,如果您閱讀錯誤消息,編譯器正試圖調用const函數。

+0

thx幫助 – yasky

+0

@yasky如果這解決了您的問題,請考慮將其標記爲已接受,方法是單擊答案旁邊的複選標記。如果你還沒有閱讀(請參閱SO瀏覽)(http://stackoverflow.com/tour)並閱讀它(如果你已經閱讀過,也許再次閱讀)。如果答案不能解決您的問題,但有幫助,請考慮投票。 –