??C++????????????????????????????
???????????? ???????[ 2013/4/24 10:02:45 ] ????????
??????????????????????????????????????????????????????????????????е?????????????
template<typename T1?? typename T2>
struct Base
{
//other function
//....
void Func(){ cout << "primary function" << endl; }
};
void test2()
{
Base<int?? int> a;
a.Func();
Base<int?? string> b;
b.Func();
}
int main()
{
test2();
}
????????????????????T2 ??string?????????????Func??????д???????????????????????????????????
??????????????????????????飬???????????????????????
????????1??
template<typename T1?? typename T2>
struct Base
{
//other function
//....
void Func()
{
if(typeid(std::string) == typeid(T2))
{
cout<<"specialization function"<<endl;
}
else
{
cout << "primary function" << endl;
}
}
};
?????????????????????????(RTTI)???????????????????????Ч??
????????2??
template<typename T1?? typename T2>
struct Base
{
//other function
//....
template<typename T>
void FuncImpl()
{
cout << "primary function" << endl;
}
template<>
void FuncImpl<string>()
{
cout << "specialization function" << endl;
}
void Func()
{
FuncImpl<T2>();
}
};
??????????????????????????
????????3??
template<typename T1?? typename T2>
struct Base
{
//other function
//....
template<typename T>
class Type2Type
{
typedef T type;
};
template<typename T>
void FunImpl(const Type2Type<T>)
{
cout << "primary function" << endl;
}
template<typename T>
void FunImpl(const Type2Type<string>)
{
cout << "specialization function" << endl;
}
void Func()
{
FunImpl<T2>(Type2Type<T2>());
}
};
??????

???·???
??????????????????
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