をコンパイルに失敗:私は取得コールは、私は次の形式のコードの一部に問題がある
:
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が前方宣言されていても、Class1 :: method1'がテンプレート関数であるとは想定できません。 'Class1'のテンプレート特化は他のところでは証明できます。 –