0

UNIXのC++で「呼び出しに一致する関数がありません」というこのビルドエラーを解決するにはどうすればよいですか?

次のビルドエラーが発生します。

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

これが私の検索機能です:

// 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;
 }

そして、これは「public:」セクションの下のLinkedSortedList.hファイルにあります。

bool find(Elem searchvalue) const;

欠落しているコードは次のとおりです。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;
4

1 に答える 1

2

問題は、エラーメッセージに示されているように、この関数を呼び出そうとしていることです。

LinkedSortedList::find(std::string&)

しかし、それは存在しません。

3つのオプションがあります。

  1. その関数を作成します。宣言(およびその後の実装)のpublicセクションでは、;のようなものを使用します。LinkedSortedListfind(const std::string&)

  2. その関数を呼び出さないでください。たとえば、テストプログラムで、list.find(elem)の代わりにを呼び出します。list.find(str)

  3. から暗黙Employee的に構築可能にしstd::stringます。これに新しいパブリックコンストラクターを追加し、パラメーターとしてEmployee単一を取りstd::stringます。

于 2012-04-30T15:22:34.227 に答える