0

The parent() function is not letting the code compile; I don't know what's wrong. The compiler is saying: expected a qualified name after typename. The constructor is working however. How to fix this?

template<typename T>
class Node {
    public:

    //accessors
    Node<T>* parent() const;

    private:
    T Data;
    Node<T>* Parent;
    std::vector<Node<T>*> Children;

};

template<typename T>
Node<T>::Node(T const & data){
    this->Data = data;
}

template <typename T>
typename Node<T>* Node<T>::parent() const {
    return this->Parent;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
scriptAddict
  • 57
  • 1
  • 5

1 Answers1

1

Your code has two issues.

The first issue is that you're missing the constructor declaration inside of the Node class. The second issue is the use of typename in the signature for parent.

typename Node<T>* Node<T>::parent() const

Node is not a nested dependent type so the use of typename is incorrect here. See this answer for more information.

Caleb
  • 284
  • 2
  • 7