Using typedef for vector of pointers in template

Viewed 81

I have a code

typedef vector<Tree *> kids_tree;

in Tree.cpp

I want to create a template code with typename DataType in TTree.inc

I tried

template <typename DataType>
std::vector<TTree<DataType> *> kids_tree;

but when I do these

kids = kids_tree();
Or
for (kids_tree::size_type i = 0; i < rhs.kids.size(); i++)

It throws an error "Use of variable template 'kids_tree' requires template arguments"

Would you please help me with this issue? How should I declare typedef of vector pointer in template class?

Thank you!!

1 Answers

Your template declares/defines a variable template, not a type-alias template.

For type-aliases you must use typedef or using:

template<typename DataType>
using kids_tree = std::vector<TTree<DataType>*>;

With that said, once you have a template, you mist provide a template argument. The symbol kids_tree by itself isn't a type, it's a template of a type. kids_tree<int> is a type.

Related