ошибка: нет подходящей функции для вызова find_name

list<SimpleList<int> *> listSLi;
list<SimpleList<double> *> listSLd;
list<SimpleList<string> *> listSLs;

Это главное:

`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

Решение

как говорится в сообщении об ошибке, компилятор не может определить тип 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?

Так что, возможно, вместо string Вы хотите T здесь, или поставьте тип прямо как find_name<string>(...)

Я не понял всей цели, но это устраняет ошибку 🙂

Улучшение:

флаг which_type вероятно, в этом нет необходимости, поскольку диспетчеризация может выполняться на уровне перегрузки. См. Тегирование (например, iterator_tags в stl) и перегрузку в целом.

3

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]