最近把一个在VS2015上正常工作的代码拿到ubuntu上用g++编译,结果编译阶段报错,开了-std=c++11也无法通过,不知道是什么原因。。
代码如下:
#include <stdio.h>
template<class A> class T {
public:
template<class B>
void func1() { printf("func1\n"); }
void func2() { printf("func2\n"); }
};
template<class A, class B>
struct F {
void func1() { T<int> t; t.func1<B>(); }
void func2() { T<A> t; t.func2(); }
void func3() { T<A> t; t.func1<B>(); }
};
int main(int argc, char *argv[]) {
F<int, int> f;
f.func3();
return 0;
}
报错位置在void F::func3()中,报错内容为:
大家帮忙看一看这个是什么原因,如果是g++支持的不够好,那如何改代码实现同样的效果呢?
在此先谢过了!