[英]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.