using
C++ 11 后的類型別名或者模板別名
類型別名是指:之前定義的類型的引用(類似 typedef)
模板別名是指:模板類的引用
語法:
(1)using identifier attr(optional) = type-id;
(2)template<template-parameter-list>
using identifier attr(optional) = type-id
identifier : 你自己聲明的變量名,可以是類型名或者模板名
type-id: 抽象類型
例子:
(1)using line_no = std::vector<string>::size_type;
相當於:typedef vector<string>::size_type line_no;
(2) // typedef void (*func)(int, int);
using func = void (*) (int, int); // the name 'func' now denotes a pointer to function
(3)template<class CharT>
using mystring = std::basic_string<CharT,std::char_traits<CharT>>;
mystring<char> str;