1

I want to create a templated binary search tree with a templated node definition inside the templated class, something like this:

template <class T>
class BST {
    template <class U>
    class BSTNode {
        BSTNode<U>* _left;

    public:
        BSTNode<U>* GetLeft();
    };
};

template <class T>
template <class U>
BST<T>::BSTNode<U>* BST<T>::BSTNode<U>::GetLeft() {
    return _left;
}

I want to define the method outside the class. When I try to compile this, I get a bunch of errors. What am I doing wrong here? Please help me, thank you very much!

Daniel C
  • 134
  • 1
  • 6
  • 1
    `typename BST::template BSTNode* BST::BSTNode::GetLeft()` – David G Mar 04 '15 at 18:50
  • Also, you *must* implement templated methods in the header in which they are defined (not sure exactly what you meant by 'outside the class'), they cannot go into a separate .cpp file. – aruisdante Mar 04 '15 at 18:51
  • @0x499602D2, You're the man! It works!@aruisdante, when I work with templates, I always put them in the same file. – Daniel C Mar 04 '15 at 19:02

0 Answers0