Dear all,

I am completely lost and I don't see at all my mistake! I thought this would be a very easy step in the building of my classes.
Thanks a lot for your help!

In the context of graph theory, I have a class Node. As attribute of this class, there is a set (called neighbours) of pointers to Node objects. When I try to compile, I get the following error.

I also have a public function addNode(*Node) which add a node pointer in the neighbours set.


class Node {
    Node(string);		// constructor (specify only the name);
    Node(string, string);	// constructor (specify the name and the color);
    // blabla
    void addNeighbour(Node*);	// add a neighbour in the set of neighbours
    // blabla
    string color;			// node color
    string name;			// node name
    set<*Node> neighbours;		// set of pointers to neighbours nodes


code of the function addNeighbours (in Node.cpp)

void Node::addNeighbour (Node* neighbour) {

The error message is the following one.

In file included from Graph.cpp:10:
Node.hpp:36: error: ‘*’ cannot appear in a constant-expression
Node.hpp:36: error: template argument 1 is invalid
Node.hpp:36: error: template argument 2 is invalid
Node.hpp:36: error: template argument 3 is invalid

Thanks again!

//set<*Node> neighbours;
set<Node*> neighbours;

It looks like you want a set of Node pointers. However, the way you wrote your declaration you are trying to use the '*' improperly. You are trying to dereference a Node object instead of declare a pointer. The '*' must be placed after the data type to declare a pointer to the data type. As in:

//set<*Node> neighbours;
set<Node*> neighbours;

Sorry I knocked you vijay, but you didn't explain...

Argh, I feel so stupid. Thank you so much to both of you!