简体   繁体   English

如何解决这个构建错误:在UNIX下的C ++中“没有匹配的函数调用”?

[英]How can I solve this build error: “no matching function for call to” in C++ under UNIX?

How can I solve this build error: "no matching function for call to" in C++ under UNIX? 如何解决这个构建错误:在UNIX下的C ++中“没有匹配的函数调用”?

I am getting the following build error: 我收到以下构建错误:

unixserver:Lab1> make
g++ -o LSL lab1.cpp Employee.cpp
lab1.cpp: In function int main():
lab1.cpp:199: error: no matching function for call to LinkedSortedList<Employee>::find(std::string&)
LinkedSortedList.cpp:137: note: candidates are: bool LinkedSortedList<Elem>::find(Elem) const [with Elem = Employee]
make: *** [main] Error 1

Here is my find function: 这是我的查找功能:

// Check to see if "value" is in the list.  If it is found in the list,
// return true, otherwise return false.  Like print(), this function is
// declared with the "const" keyword, and so cannot change the contents
// of the list.
template<class Elem>
bool LinkedSortedList<Elem>::find(Elem searchvalue) const {
         if (head == NULL) {
                 return false;
         } else {
                 while (head != NULL) {
                    LinkedNode<Elem>* pointer;
                    for (pointer = head; pointer != NULL; pointer = pointer->next) 
                        if (pointer->value == searchvalue) {
                            return true;
                        }
                  }
         }
         return false;
 }

And this is in my LinkedSortedList.h file under the "public:" section: 这是在我的LinkedSortedList.h文件下的“public:”部分:

bool find(Elem searchvalue) const;

Here is the missing code: line 199 这是缺少的代码:第199行

                        case 'S':
                                cout << "Save database to a file selected\n\n";
                                // TODO call function to save database to file
                                // File I/O Save to file
                                cout << "Please enter a file name: " << endl;
                                cin >> fileName;
                                {char* file = (char*) fileName.c_str();
                                writeFile(file, database);}
                                break;

Your problem is, as the error message states, that you are trying to invoke this function: 正如错误消息所述,您的问题是您尝试调用此函数:

LinkedSortedList::find(std::string&)

but it doesn't exist. 但它不存在。

You have three options: 你有三个选择:

  1. Create that function. 创建该功能。 In the public section of LinkedSortedList declare (and subsequently implement) something like find(const std::string&) ; LinkedSortedListpublic部分声明(并随后实现)像find(const std::string&) ;

  2. Don't invoke that function. 不要调用该功能。 In your test program, call list.find(elem) instead of list.find(str) , for example. 例如,在测试程序中,调用list.find(elem)而不是list.find(str)

  3. Make Employee implicitly constructable from std::string . 使用std::string隐式构造Employee Add a new public constructor to Employee that takes a single std::string as a parameter. Employee添加一个新的公共构造函数,它将一个std::string作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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