error C2146 and error C2501

Discussion in 'C++' started by Tim, Sep 9, 2004.

  1. Tim

    Tim Guest

    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
     
    Tim, Sep 9, 2004
    #1
    1. Advertising

  2. "Tim" <> wrote in message
    news:...
    > 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
     
    John Harrison, Sep 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,752
  2. JavaQueries
    Replies:
    1
    Views:
    3,771
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,201
  4. Bishop
    Replies:
    1
    Views:
    832
    Bishop
    Feb 24, 2007
  5. BlackHelicopter
    Replies:
    2
    Views:
    694
    BlackHelicopter
    Feb 12, 2013
Loading...

Share This Page