c++11别名模板

#include <iostream>
#include <map>
#include <boost/type_index.hpp>
using namespace std;
//别名模板
template<typename T>
using str_map_t = std::map<std::string, T>;

template<typename T>
class E
{
    
    
	//成员别名模板
	template<typename T>
	using str_map_t = std::map<std::string, T>;
public:
	str_map_t<int> map1;
};

int main()
{
    
    
	/*别名模板与成员别名模板
	别名模板 = "Alias Templates",C++11新标准中引入的,
	引入的目的不但能简化书写,而且可以达到一些通过其他手段难以达到的效果*/
	str_map_t<int> map1;
	map1.insert({
    
     "first",1 });
	map1.insert({
    
     "second",2 });

	E<float> obja;
	obja.map1.insert({
    
     "first",1 });
	obja.map1.insert({
    
     "second",8 });
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38158479/article/details/121069478