??C++????????????????????????????
???????????? ???????[ 2013/4/24 10:02:45 ] ????????
?????????????C++????????????????????????????????? ?????????д??????????е????к????? ??????Щ????????????????? ???????Щ???????????????????????????????????????????????????????£????????????????????????????Щ??????????????? ???????????????в???????????????
????????????????????
template<typename T?? unsigned B>
struct Base
{
//other function
//....
void Func(){ cout << "primary function" << endl; }
};
void test1()
{
Base<int?? 1> a;
a.Func();
Base<int?? 16> b;
b.Func();
}
int main()
{
test1();
}
??????е?B????16??? Func??????????????? ????????????????????????????????
????????????????Щ????????????
????????1??
template<typename T>
struct Base<T?? 16>
{
//other function
//....
void Func(){ cout << "specialization function" << endl; }
};
??????????????????????????д???е???????????
????????2??
template<typename T?? unsigned B>
struct Base
{
//other function
//....
void Func()
{
if(B == 16)
{
cout << "primary function" << endl;
}
else
{
cout << "specialization function" << endl;
}
}
};
???????????????????ж?????????????????Ч??
????????3??
template<typename T?? unsigned B>
struct Base
{
//other function
//....
void Func()
{
#if B!=16
cout << "primary function" << endl;
#else
cout << "specialization function" << endl;
#endif
}
};
?????????????????????????????????????????????C++??????????????????飬???????????Σ???????????????????????????????
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11