如何解决此生成错误:“quot;没有与“调用”匹配的函数;在C++;在UNIX下? 中C++中没有调用函数的匹配函数

如何解决此生成错误:“quot;没有与“调用”匹配的函数;在C++;在UNIX下? 中C++中没有调用函数的匹配函数,c++,unix,build,C++,Unix,Build,我收到以下生成错误: 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: cand

我收到以下生成错误:

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
这是丢失的代码:第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;
case'S':

cout正如错误消息所述,您的问题是,您正试图调用此函数:

// 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;
 }
LinkedSortedList::find(std::string&)
但它并不存在

您有三种选择:

  • 创建该函数。在
    LinkedSortedList
    public
    部分中,声明(并随后实现)类似于
    find(const std::string&)

  • 不要调用那个函数。例如,在测试程序中,调用
    list.find(elem)
    而不是
    list.find(str)

  • 使
    Employee
    可以从
    std::string
    隐式构造。向
    Employee
    添加一个新的公共构造函数,该构造函数将单个
    std::string
    作为参数


  • 请不要像这样在代码中张贴行号;这使得任何人都很难复制并粘贴到编辑器中。此外,您还没有发布导致错误的代码(即第199行和上面的任何其他相关行)。请格式化您的代码。还有编译器输出示例。我发布了丢失的代码,对此很抱歉。发布时如何格式化代码?
    LinkedSortedList::find(std::string&)