2017-01-02 2 views
0
list<SimpleList<int> *> listSLi; 
list<SimpleList<double> *> listSLd; 
list<SimpleList<string> *> listSLs; 

find_nameへの呼び出しに該当する機能は:エラー:これがメインです

`int main() { 
     cout << "Enter name of input file: "; 
     string input_f; 
     cin >> input_f; 

    /* cout << "Enter name of output file: "; 
    string output_f; 
    cin >> output_f; 
    */ 
    ifstream input(input_f); 
    // ofstream output(output_f); // Make this a separate function 

    string to_parse; 
    vector<string> sep_words; 
    while (getline(input, to_parse)) { 
    // cout << "PROCESSING COMMAND: " << to_parse << '\n'; 
    to_parse += '\n'; // getline removes the \n on each line 
    sep_words = parse_line(to_parse); 
    cpp(sep_words); 
    } 
    return 0; 
} 

これはSimpleListクラスです。派生クラスはスタックとキューです。

template<typename T> 
class SimpleList { 
public: 
    SimpleList(); 
    SimpleList(const string& n); 
    virtual void push(T value) =0; 
    virtual void pop() =0; 
    void set_name(const string&); 
    string get_name(); 
protected: 
    void insert_front(T); 
    void insert_back(T); 
    void remove_front(); 
    // Should be protected: 
    Node<T> first, last, temp; 
    string name; 
    int size; 
}; 

sep_wordsには2文字または3文字の文字列が含まれます。

void cpp(const vector<string>& single_words) {///////////////////////// 
    if (single_words.size() == 2) { // pop 
    switch(single_words[1][0]) { 
    case 'i': 
     if(is_name_in(single_words[1], 0) != true) { 
     cout << "ERROR: This name does not exist!\n"; 
     return; 
     } 
     else if (is_list_empty(single_words[1], 0)) { // add == true for readability 
     cout << "ERROR: This list is empty!\n"; 
      return; 
     } 
     else { 
312  find_name(single_words[1], 0)->pop(); 
     } 
     break; 

find_name(single_words [1]、0) - > pop();問題のあるライン

template<typename T> 
SimpleList<T>* find_name(const string& nm, int which_type) { // Can do char which_type instead 
    // 0 stands for integer 1 stands for double 2 stands for string 
    switch(which_type) { 
    case 0: 
    for (list<SimpleList<int> *>::iterator it = listSLi.begin(); it != listSLi.end(); ++it) { 
     if ((*it)->name == nm) { // Use get_name instead 
     return *it; 
     } 
    } 
    break; 
    case 1: 
    for (list<SimpleList<double> *>::iterator it = listSLd.begin(); it != listSLd.end(); ++it) { 
     if ((*it)->name == nm) { 
     return *it; 
     } 
    } 
    break; 
    case 2: 
    for (list<SimpleList<string> *>::iterator it = listSLs.begin(); it != listSLs.end(); ++it) { 
     if ((*it)->name == nm) { 
     return *it; 
     } 
    } 
    break; 
    } 
} 

はここでコンパイルエラーですです:エラー・メッセージ・サイスとして

main.cpp: In function ‘void cpp(const std::vector<std::basic_string<char> >&)’: 
main.cpp:312:31: error: no matching function for call to ‘find_name(const value_type&, int)’ 
    find_name(single_words[1], 0)->pop(); 
          ^
main.cpp:312:31: note: candidate is: 
main.cpp:272:16: note: template<class T> SimpleList<T>* find_name(const string&, int) 
SimpleList<T>* find_name(const string& nm, int which_type) { // Can do char which_type instead 
       ^
main.cpp:272:16: note: template argument deduction/substitution failed: 
main.cpp:312:31: note: couldn't deduce template parameter ‘T’ 
    find_name(single_words[1], 0)->pop(); 
          ^
+0

あなたの質問でmain.cppに312行目をマークしてください –

+0

本当に 'find_name'がテンプレート関数である必要がありますか?現在のところ、 'SimpleList *'を返しています。 – ForceBru

+0

長すぎるかもしれないので、私は関数全体を表示しませんでしたが、残りのコードでは倍精度と文字列を使用します。 – user1692570

答えて

3

は、コンパイラは、テンプレートで型Tを推定傾けます。

template<typename T> 
SimpleList<T>* find_name(const string& nm, int which_type); .... 

ここで、タイプTは関数のパラメータです。しかし、コンパイラは引数の中に現れないので、あなたが意味する型を知ることができません。

const string& nm, int which_type // what shall be T? 

だから多分あなたはここにTをしたい、またはfind_name<string>(...)

のような直接の種類を供給する代わりにstringの私は、全体の目的を理解していなかったが、それは誤り:)

強化住所が:

フラグwhich_typeは、過負荷レベルでディスパッチできるため、おそらく不要です。タグ付け(例:stlのiterator_tags)と一般的なオーバーロードを参照してください。

関連する問題