我刚学了几页有关模板的内容,并遇到以下问题。
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>();
....