Template Aliases (C++11)
It can be convenient, especially in template design, to create aliases for types. You can use typedef
to create aliases for template specializations:
// define three typedef aliasestypedef std::array<double, 12> arrd;typedef std::array<int, 12> arri;typedef std::array<std::string, 12> arrst;arrd gallons; // gallons is type std::array<double, 12>arri days; // days is type std::array<int, 12>arrst months; // months is type std::array<std::string, 12>
But if you find yourself writing code similar to the preceding typedef
s, over and over, you might wonder if you’ve forgotten some language feature that simplifies the task or if the language has forgotten to supply such a feature. In this case, C++11 provides a feature ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.