关于C ++模板的基本问题

时间:2011-08-01 10:27:32

标签: c++ templates arm

考虑这个过于简单的测试:

class foo
{
    public:
        foo(int i);
        template< typename T > foo(T);
};

template<> foo::foo(int i) {}

现在,GCC很乐意在编译时接受这个,但RVCT编译器发出错误:

test.cpp", line 11: Error:  #792: "foo::foo(int)" is not an entity that can be explicitly specialized
 template<> foo::foo(int i) {}

除非“为什么要这样做”这个问题,这个合法的C ++(从学术角度来看?)

提前致谢

1 个答案:

答案 0 :(得分:3)

您正在尝试对template<typename T> foo(T)进行明确的专业化,其中T = int。

你真的想要这个吗?

template<typename T> foo::foo(T) {
}

---编辑---

为了说清楚:“显式专业化”在C ++中是合法的,但显然你的编译器不支持它(无论如何,在个别方法上,也许它在整个类上都有用?)。