1

I have a BinNode<Elem> class for my Binary Search Tree Implementation.

When I initialise the following: deque< BinNode<Elem>* >::const_iterator iter = n.begin(); I get an error telling me that a colon is expected after deque<>.

Does the deque not support a template argument in a template argument or is this some sort of different error?

Here is a snippet of the function:

template <class Key, class Elem, class KEComp, class EEComp>
void BST<Key, Elem, KEComp, EEComp>::
printBranchesHelp(int branchLen, int nodeSpaceLen, int startLen, int nodesInThisLevel, const deque< BinNode<Elem>* >& n, ostream& out)
{
    deque< BinNode<Elem>* >::const_iterator iter = n.begin();
    for (int i = 0; i < nodesInThisLevel / 2; i++) 
    {  
        out << ((i == 0) ? setw(startLen-1) : setw(nodeSpaceLen-2)) << "" << ((*iter++) ? "/" : " ");
        out << setw(2*branchLen+2) << "" << ((*iter++) ? "\\" : " ");
    }
    out << endl;
}  
Kevin Zakka
  • 445
  • 7
  • 19

1 Answers1

2

Since deque< BinNode<Elem>* >::const_iterator is a dependent name, you need to explicitly identify it as a type with the typename keyword:

typename deque< BinNode<Elem>* >::const_iterator iter = n.begin();

You might want to look at this question for a better understanding of dependent names and why you need to use typename.

If you find yourself needing this type a lot, I'd recommend writing an alias or typedef for it:

using deque_iterator = typename deque< BinNode<Elem>* >::const_iterator;

Or in C++11 you could just sidestep the issue and use auto:

auto iter = n.begin();
Community
  • 1
  • 1
TartanLlama
  • 63,752
  • 13
  • 157
  • 193