How to instantiate and rename a template class

Viewed 37

Description

I declared a template class

template <typename T,size_t RootNum>
class Tree;

And I want to specialize another template class BinaryTree, whose RootNum is 2, but every members is identicial with class Tree.
An inelegant method is defining a class BinaryTree inherits class Tree as below

template <typename T>
class BinaryTree: public Tree<T,2>{};

But I vaguely remember that it exists a declaration simillar to this style to 'elegantly' specialize a template class:

template <typename T>
typedef Tree<T,2> BinaryTree;

Actually the above code is invalid. I wonder is there a keyword-like to concisely achive this operation.

Thank you for your kind suggession.

1 Answers

You are looking for an alias template:

template <typename T>
using BinaryTree = Tree<T,2>;
Related