C++???????????????????????????
???????????? ???????[ 2015/7/14 13:23:06 ] ??????????????????? ????????
????????????????????????(??????)???????壬?????????????????г??????????????д???????????????????????????????????????????????????1??2????????????ɡ???????????£?????????д???????????г?????????????????????????????????????????
??????????????????A???????????????char*????????????????func()????????????????????????????
1 template <typename _Ty>
2 struct A
3 {
4 // ???????????a
5 // ???????????b
6 // ......
7 void func()
8 {
9 std::cout << "common type." << std::endl;
10 }
11 };
12
13 int main()
14 {
15 A<int> i;
16 i.func();
17
18 A<char*> c;
19 c.func();
20
21 return 0;
22 }
???????????????????????????????????
1 template <typename _Ty>
2 struct A
3 {
4 // ???????????a
5 // ???????????b
6 // ......
7 void func()
8 {
9 if (typeid(_Ty) == typeid(char*))
10 std::cout << "common type." << std::endl;
11 else
12 std::cout << "special type." << std::endl;
13 }
14 };
????????????????????????????????????????????????
1template<typename_Ty>
2structA
3{
4//???????????a
5//???????????b
6//......
7template<typename__Ty>
8voidfuncImpl()
9{
10std::cout<<"commontype."<<std::endl;
11}
12
13template<>
14voidfuncImpl<char*>()
15{
16std::cout<<"specialtype."<<std::endl;
17}
18
19voidfunc()
20{
21funcImpl<_Ty>();
22}
23};
??????
???·???
??????????????????
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