Reputation:
I have the following template declaration:
template <typename T1, typename T2>
class tree{
public:
tree(int,T2&);
~tree();
...
rNodePtrIter travPreord(int);
void travInord();
rNodePtrIter travInord(int);
void travPostord();
rNodePtrIter travPostord(int);
private:
NodePtrIter hierarchy;
};
I declared the type rNodePtrIter just above the template declaration as follows:
using rNodePtrIter = list<unique_ptr<node<T1>>>::iterator&;
That doesn't compile as the compiler complains that the type T1 is not known:
error: use of undeclared identifier 'T1'
Is there a way to get in the using declaration as above, so that I could use the alias rNodePtrIter in my template declaration, instead of the longer alternative?
TIA
Vinod
Upvotes: 0
Views: 60
Reputation: 17483
You might use alias template:
template<typename T1>
using rNodePtrIter = typename list<unique_ptr<node<T1>>>::iterator&;
and then replace rNodePtrIter
inside the class with rNodePtrIter<T1>
.
Upvotes: 2
Reputation: 37485
Just move type alias declaration inside of template:
template <typename T1, typename T2>
class tree{
public: using rNodePtrIter = typename list<unique_ptr<node<T1>>>::iterator&;
Note that it requires node
template to be already declared.
Upvotes: 2