2013-05-19 2 views
2

나는 코드의이 비트를 들어 다음과 같은 컴파일러 오류오류 : 호출 (표준 : : 문자열 &)

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

당신은 명시 적으로 템플릿 매개 변수를 제공해야합니다 : Foo이 템플릿 tnode 클래스에 제공되는 클래스 유형입니다

infxTree<Foo>(infxStr) 

.

+0

감사합니다! 이 프로그램은 여전히 ​​작동하지 않지만 최소한 컴파일해야하므로 이유를 알아낼 수 있습니다! 감사합니다. – Gray

3

T가 무엇인지에 대한 함수 서명에 단서가 없으므로이를 템플릿 유형 매개 변수로 명시 적으로 지정해야합니다.

inxTree<int>(infxStr); 

당신이 T에 따라 인수가 있다면 이것은 컴파일러가 타입 추론하는 데 사용할 수있는, 생략 할 수 있습니다 :

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