dimanche 17 mai 2015

C++ Nested class in class template declaration

I'm attempting to write a C++11 linked list implementation, with the linked list being a template class and its node being a nested class as follows:

template <typename T>
class LinkedList {
public:
    class Node;
    std::shared_ptr<Node> listSearch(const T &input) const;

private:
    std::shared_ptr<Node> head;
    std::shared_ptr<Node> tail;
};

template <typename T>
class LinkedList<T>::Node {
private:
    T data;
    std::shared_ptr<Node> next;
}

I am assuming that the class Node is not a template in itself, but when LinkedList gets instantiated it creates the Node class as well.

When I attempt to define the listSearch function as follows, I get an error: "template argument for template type parameter must be a type; did you forget 'typename'?". Can someone explain what is wrong?

template <typename T>
std::shared_ptr<LinkedList<T>::Node> LinkedList<T>::listSearch(const T &input) { ... }

Aucun commentaire:

Enregistrer un commentaire