美文网首页
深入理解C++11 3.10 模板的别名 using

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

作者: zinclee123 | 来源:发表于2019-10-31 18:41 被阅读0次

在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;

相关文章

网友评论

      本文标题:深入理解C++11 3.10 模板的别名 using

      本文链接:https://www.haomeiwen.com/subject/klotbctx.html