Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error C2146 and error C2501

Reply
Thread Tools

error C2146 and error C2501

 
 
Tim
Guest
Posts: n/a
 
      09-09-2004
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
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-09-2004

"Tim" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emacs VHDL-mode Next-Error, Previous-Error, and First-Error are not working...? BlackHelicopter VHDL 2 02-12-2013 01:12 AM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM



Advertisments