error C2146 and error C2501

T

Tim

I created a header file including a Node Class and a
NodeList Class.

class Node{
Node* next;
};

class NodeList{
Node* first;
Node* last;
};

I wanna declare a NodeList inside the Node but since
NodeList is declared after Node it gives me this error

class Node{
Node* next;
NodeList list;
};


I get:
error C2146: syntax error : missing ';' before identifier 'list'
error C2501: 'Node::list' : missing storage-class or type specifiers
error C2501: 'Node::NodeList' : missing storage-class or type
specifiers

I tried to include both in different header files with each one
referencing the other but it was a wrose idea since the linker was
looping

Is there any way I can overcome this?
Thank you
 
J

John Harrison

Tim said:
I created a header file including a Node Class and a
NodeList Class.

class Node{
Node* next;
};

class NodeList{
Node* first;
Node* last;
};

I wanna declare a NodeList inside the Node but since
NodeList is declared after Node it gives me this error

class Node{
Node* next;
NodeList list;
};


I get:
error C2146: syntax error : missing ';' before identifier 'list'
error C2501: 'Node::list' : missing storage-class or type specifiers
error C2501: 'Node::NodeList' : missing storage-class or type
specifiers

I tried to include both in different header files with each one
referencing the other but it was a wrose idea since the linker was
looping

Is there any way I can overcome this?
Thank you

Put the following in one header file

class Node; // forward declaration

class NodeList{
Node* first;
Node* last;
};

class Node{
Node* next;
NodeList list;
};

One class per header file is a good idea in general, but its not when
classes are as tightly dependent on each other as these two are.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top