何时何时不专门化模板实例

时间:2018-01-17 18:12:23

标签: c++

我刚学了几页有关模板的内容,并遇到以下问题。 A.h

struct A
{
   template<class T> T func();
}; 

A.cpp

template<class T>
T func()
{
   //do something
}

template<> int A::func<int>();
template<> char A::func<char>();

现在,如果我有这个结构

template<class C>
struct B
{
    template<typename T>
    T func();
};

func与特定class C使用时,我是否必须写出所有案例?

e.g 
template<classX> int func<int>();
template<classX> char func<char>();
template<classY> int func<int>();
....

0 个答案:

没有答案