010using关键字自定义数据类型
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include <map>
using namespace std;
typedef unsigned int uint;
using u_int = unsigned int;
typedef std::map<std::string, int> myMap;
using myMap006 = std::map<std::string, int>;
template <typename T>
class map_s
{
public:
typedef std::map<std::string, T > mymap02;
};
template<typename T>
using str_map_t = std::map<string, T>;
using myFunction = void(*)(int, int);
typedef void(*myFunction02)(int, int);
template<typename T>
using myFunction_m = int(*)(T, T);
int testFunction(int a,int b)
{
return a + b;
}
int main(void)
{
uint a = 10;
myMap map1;
map1.insert({ "aaaa", 1 });
map1.insert({ "bbbb",2 });
map_s<int>::mymap02 map001;
map001.insert({ "aaaaa",1 });
map_s<string>::mymap02 map002;
map002.insert({ "bbbbb","2" });
str_map_t<int> map003;
map003.insert({ "dfsdf",3 });
myFunction_m<int> pointFunc;
pointFunc = testFunction;
cout << pointFunc(23, 45) << endl;
system("pause");
return 0;
}
011显式指定模板参数
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include <map>
using namespace std;
template<typename T1,typename T2,typename T3>
T1 Sum(T1 i,T3 j)
{
T1 result = i + j;
return result;
}
int main(void)
{
auto result = Sum<int, int, int>(2000000000, 2000000000);
auto restult02 = Sum<double, int, int>(2000000000, 2000000000);
cout << result << endl;
cout << restult02 << endl;
system("pause");
return 0;
}