相关疑难解决方法(0)

模板类专业化的模板方法

这是我的代码:

template<typename T1, typename T2> class MyClass
{
public:
    template<int num> static int DoSomething();
};

template<typename T1, typename T2> template<int num> int MyClass<T1, T2>::DoSomething()
{
    cout << "This is the common method" << endl;
    cout << "sizeof(T1) = " << sizeof(T1) << endl;
    cout << "sizeof(T2) = " << sizeof(T2) << endl;
    return num;
}
Run Code Online (Sandbox Code Playgroud)

它运作良好.但是当我尝试添加这个

template<typename T1, typename T2> template<> int MyClass<T1, T2>::DoSomething<0>()
{
    cout << "This is ZERO!!!" << endl;
    cout << "sizeof(T1) = " << sizeof(T1) << …
Run Code Online (Sandbox Code Playgroud)

c++ linux templates g++

10
推荐指数
1
解决办法
3470
查看次数

标签 统计

c++ ×1

g++ ×1

linux ×1

templates ×1