Reputation: 698
How can I solve this build error: "no matching function for call to" in C++ under UNIX?
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:
bool find(Elem searchvalue) const;
Here is the missing code: line 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;
Upvotes: 0
Views: 295
Reputation: 168786
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:
Create that function. In the public
section of LinkedSortedList
declare (and subsequently implement) something like find(const std::string&)
;
Don't invoke that function. In your test program, call list.find(elem)
instead of list.find(str)
, for example.
Make Employee
implicitly constructable from std::string
. Add a new public constructor to Employee
that takes a single std::string
as a parameter.
Upvotes: 2