gcc在线编译:https://c.runoob.com/compile/12/
#includeusing namespace std; class XXX { public: template B convert(int a) { return 3; } }; template int f(T* x) { return x->convert (4); //这里在gcc上编译会报错,在vs里编译是正常的 } int main() { XXX x; int xx = f(&x); return 0; }
改为明确指定的方式:
#includeusing namespace std; class XXX { public: template B convert(int a) { return 3; } }; template int f(T* x) { return x->template convert (4); //这里必须使用->template的方式调用,如果使用*的方式调用:(*x).template convert (4); } int main() { XXX x; int xx = f(&x); return 0; }



