를 컴파일 실패 : 내가 얻을전화 나는 다음과 같은 형태의 코드 조각에 문제가
:
template<class Type>
class Class1 {
public:
template<class TypeName1> TypeName1* method1() const {return 0;}
};
struct Type1{};
struct Type2{};
class Class2 {
public:
template<typename TypeName1, typename TypeName2>
int method2() {
Class1<TypeName2> c;
c.method1<TypeName1>();
return 0;
}
int method1() {
return method2<Type1, Type2>();
}
};
int
main() {
Class2 c;
return c.method1();
}
codepad에서 컴파일러로 컴파일 할 때 다음 오류 :
t.cpp: In member function 'int Class2::method2()': Line 15: error: expected primary-expression before '>' token compilation terminated due to -Wfatal-errors.
불쾌한 줄은 템플릿 멤버 함수 :
c.method1<TypeName1>();
좋은 답변입니다. 끔찍한 언어. –
매력처럼 작용하여 5 분 안에 받아 들일 것입니다! –
+1. 특히이 문맥에서 'Class1'이 forward-declared 인 경우에도'Class1 :: method1'이 템플릿 함수라고 가정 할 수 없습니다. Class1의 템플릿 전문화는 다른 곳에서 증명 될 수 있습니다. –