简体   繁体   English

错误:没有匹配函数来调用...(std :: string&)

[英]error: no matching function for call to…(std::string&)

I'm getting the following compiler error 我收到以下编译器错误

error: no matching function for call to 'infxTree(std::string&)' 错误:没有匹配函数来调用'infxTree(std :: string&)'

For this bit of code. 对于这段代码。

int main(){
string infxStr;

cout << "Enter an infix string: " << endl;
cin >> infxStr;


prefixOutput(infxTree(infxStr));
postorderOutput(infxTree(infxStr), ' ');
displayTree(infxTree(infxStr), infxStr.size());
    return 0;

} }

I get the error on all the last 3 lines. 我收到了最后3行的错误。 Here's the function: 这是功能:

template <typename T>
tnode<T> infxTree(const string& iexp);

Any ideas what I'm doing wrong? 有什么想法我做错了吗? Thanks! 谢谢!

You have to give the template parameter explicitly: 您必须明确地提供模板参数:

infxTree<Foo>(infxStr)

Where Foo is the class type provided to your templated tnode class. 其中Foo是提供给模板化tnode类的类类型。

Since there is no clue in the function signature as to what T is, you have to specify it explicitly as a template type parameter. 由于函数签名中没有关于T是什么的线索,因此必须将其明确指定为模板类型参数。

inxTree<int>(infxStr);

This can be omitted if you have any arguments that depend on T, that the compiler can use to infer the type: 如果您有任何依赖于T的参数(编译器可以用来推断类型),则可以省略此参数:

node<T> inxTree(string str, T item) { /* ... */ }
int item;
inxTree(infxStr, item); // OK

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配函数可调用&#39;isupper(std :: string&)&#39;| - error: no matching function for call to 'isupper(std::string&)'| 错误:没有用于调用“getline(FILE*&amp;, std::string&amp;)”的匹配函数 - error: no matching function for call to 'getline(FILE*&, std::string&)' 字符串的排列-错误:没有匹配的函数来调用&#39;std :: set <char> :: insert(std :: string&)&#39; - Permutations of a string --error: no matching function for call to ‘std::set<char>::insert(std::string&)’ 为什么这个编译错误? - 没有匹配函数来调用&#39;std :: basic_ofstream <char> ::打开(的std :: string&)” - why this compiler error? - no matching function for call to 'std::basic_ofstream<char>::open(std::string&)' 使用 getline 给出错误:没有匹配的 function 调用 'getline(std::istream&amp;, const string&amp;)' - using getline gives error: no matching function for call to ‘getline(std::istream&, const string&)’ 错误:没有匹配的函数调用&#39;std::basic_ifstream<char> ::basic_ifstream(std::__cxx11::string&amp;)&#39; - error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)' “没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'” - “no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’” 没有匹配的 function 调用 'std::vector::push_back(std::string&amp;)' - No matching function for call to ‘std::vector::push_back(std::string&)’ 没有匹配的 function 调用 'LiquidCrystal::write(String&amp;)' - no matching function for call to 'LiquidCrystal::write(String&)' 为什么C ++中的getline()无法正常工作? (没有匹配函数可调用“ getline(std :: ofstream&,std :: string&)” - Why is getline() in C++ not working? (no matching function for call to 'getline(std::ofstream&, std::string&)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM