使用別名宣告

Version >= C++ 11

using 的語法非常簡單:要定義的名稱位於左側,定義位於右側。無需掃描即可檢視名稱的位置。

using I = int;
using A = int[100];             // array of 100 ints
using FP = void(*)(int);        // pointer to function of int returning void
using MP = void (Foo::*)(int);  // pointer to member function of Foo of int returning void

使用 using 建立型別別名與使用 typedef 建立型別別名具有完全相同的效果。它只是完成同樣事情的另一種語法。

typedef 不同,using 可以模板化。使用 using 建立的 template typedef 稱為別名模板