2013-05-19 93 views
2

我得到以下編譯器錯誤錯誤:調用...(的std :: string&)

error: no matching function for call to 'infxTree(std::string&)'

對於該位的代碼不匹配功能。

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; 

}

我得到的所有的最後3行錯誤。這裏的功能:

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

任何想法我做錯了什麼?謝謝!

回答

4

你必須給明確的模板參數:

infxTree<Foo>(infxStr) 

哪裏Foo是提供給您的模板tnode類的類類型。

+0

謝謝!該程序仍然不起作用,但至少現在它編譯,所以我可以嘗試找出原因!多謝。 – Gray

3

由於函數簽名中沒有關於T是什麼的線索,所以必須明確指定它作爲模板類型參數。

inxTree<int>(infxStr); 

這可以,如果你有依賴於T任何參數,可以省略,編譯器可以用它來推斷類型:

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