-2

I have a node class which can store data of any type.

This is my code right now. I'm getting a error C2059: syntax error : '<' on friend class List;

template <typename T>
class Node{
protected:
    T info;
    Node *urm;
    Node *ant;
public:
    int get_info() { return info; }
    void set_info(T a) { info = a; }
    friend class List<T>;
};

template <typename T>
class List{
protected:
    Node<T> *p, *u;
public:
};
Shury
  • 468
  • 3
  • 15
  • 49
  • Also, don't edit the question and change the code dramatically, since the initial answers will look completely out of context. – vsoftco May 17 '15 at 17:42

2 Answers2

2

Node is a class template and it expects a template argument at instantiation. So you have to specify it, something like

Node<int> *p, *u; // Nodes of integers
    ^^^^^
    instantiate the template with int

Since your Node is a class template, I suggest making List a class template too, as otherwise List loses the ability of manipulating arbitrary types

template <typename T>    
class List{
protected:
    Node<T> *p, *u;
public:
};

UPDATE (but please do not change your code and question live, better ask a new one)

You should also provide a forward declaration of List, as otherwise it is not visible when declaring the friend in Node. In other words, put this line

template<typename T>
class List; // forward declaration

above the declaration of Node.

vsoftco
  • 55,410
  • 12
  • 139
  • 252
1

Try this :

template<typename T>
class List{
    protected:
    Node<T> *p, *u;
    public:
};

You need to provide a template argument list to Node to create its objects.

0x6773
  • 1,116
  • 1
  • 14
  • 33