typedef 重命名回顾
//typedef 在C 和 C++上的使用
typedef unsigned int int_yyy;// 给 unsigned int 重新命名为 int_yyy
typedef map<int, string> maps_i;//给 map<int, string> 重新命名为 maps_i
typedef void(*FUNCTYPE)(int);//定义一个函数指针类型。
typedef FUNCTYPE ttt;//给FUNCTYPE 这种类型重新命名为ttt
//现在的需求是:要在map中key 为string,但是value 是不确定的值,在C中的写法是要借助 模版类完成
template <typename T>
class teacher101 {
public:
typedef map<string, T> ddd; //给 map<string,T> 这种类型 重新名为为ddd
};
void func100(int a) {
cout << "func100 a = " << a << endl;
}
void main(){
cout << " typedef 在 C 和 C++中的使用举例 " << endl;
int_yyy aaa = 10;
maps_i bbb;
bbb.insert({1,"nihao"});
bbb.insert({2,"mnbnmlm"});
ttt ccc = func100;
ccc(898989);
//map 的使用
teacher101<double>::ddd mapsiii;//teacher101<double>是作用域,ddd是类型, mapsiii是变量名
mapsiii.insert({ "ss",98.9 });
mapsiii.insert({ "ww",989090.9 });
//打印值验证
cout << mapsiii["ss"] << endl;
}
using 重命名 study
//现在的需求是:要在map中key 为string,但是value 是不确定的值,在C中的写法是要借助 模版类完成
template <typename T>
class teacher101 {
public:
typedef map<string, T> ddd; //给 map<string,T> 这种类型 重新名为为ddd
};
//C++11 using 解决方案
template <class T>
using str_map_t = map<double, T>;//str_map_t 为类型别名
//using的其他使用方法
using uiui = unsigned int ;
using maps_using = map<string, int>;
void main() {
//使用
str_map_t<int> aaa;
aaa.insert({ 20.1,89 });
aaa.insert({ 20.2,82229 });
cout << "value =" << aaa[20.1] << endl;
cout << "value =" << aaa[20.2] << endl;
//使用
uiui bbb = 9;
maps_using mapsusing;
mapsusing.insert({"aa",67});
mapsusing.insert({"bb",90});
cout << mapsusing["aa"] << endl;
cout << mapsusing["bb"] << endl;
}