我对以下形式的一段代码有疑问:
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();
}
在键盘上使用编译器编译时:
我收到以下错误:
t.cpp:在成员函数“int Class2::method2()”中:第 15 行:错误:“>”标记编译之前的预期主表达式由于 -Wfatal 错误而终止。
违规行是模板成员函数的调用:
c.method1<TypeName1>();