深入理解C++11 3.10 模板的别名 using

2019-10-31  本文已影响0人  zinclee123

在C++中,可以如下使用typedef

typedef std::vector<std::string> strvec;

在C++11中可以使用using实现同样的功能,如:

using namespace std;

using uint = unsigned int;
typedef unsigned int UINT;

int main(){
    cout << is_same<uint, UINT>::value << endl; // 输出1
    return 0;
}

在使用模板编程的时候,using的语法比typedef更加灵活,如:

template<typename T> using MapString = std::map<T, char*>;

MapString<int> numberedString;
上一篇 下一篇

猜你喜欢

热点阅读