For example
struct Option_1
{
template<class T> using Vector = std::vector<T>;
};
I can do
typename Option_1::Vector<int> v;
But I prefer the following
Vector<Option_1, int> v;
or similars without the word "typename". I define an alias
template<class Option, class T> using Vector= typename Option::Vector<T>;
but failed with unrecognizable template declaration/definition. How to fix it?
Type alias is a name that refers to a previously defined type (similar to typedef). Alias template is a name that refers to a family of types.
You can use an alias declaration to declare a name to use as a synonym for a previously declared type. (This mechanism is also referred to informally as a type alias). You can also use this mechanism to create an alias template, which can be useful for custom allocators.
You must add the keyword typename to the beginning of this declaration: typename A::C d; You can also use the keyword typename in place of the keyword class in template parameter declarations.
Inheriting from a template classIt is possible to inherit from a template class. All the usual rules for inheritance and polymorphism apply. If we want the new, derived class to be generic it should also be a template class; and pass its template parameter along to the base class.
You should use the keyword template for the dependent template name Option::Vector
, i.e.
template<class Option, class T> using Vector = typename Option::template Vector<T>;
// ~~~~~~~~
LIVE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With