Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ compilation problems

Options
  • 15-03-2001 3:50am
    #1
    Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭


    I have two classes (ObjectList and ObjectNode) which both refer to each other (ie ObjectList contains an ObjectNode pointer and vice versa). However when I try to compile the program I can't get these two classes to compile because they're both looking for each other (I think).

    Am I [not] doing something stupid?


Comments

  • Subscribers Posts: 1,911 ✭✭✭Draco


    Why does your ObjectNode refer to ObjectList?
    Is it a linked list you're writing?
    What you need to do is make a forward declaration of the classes:

    //forward declaration of ObjectNode
    class ObjectNode;

    class ObjectList{
    public:
    blah blah blah

    };

    If you are make a linked list, you shouldn't have to refer to ObjectList in the ObjectNode class.

    Draco


  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Well it's a linked list, but every node contains a sub-list of nodes, sort of a tree.

    I put in forward declarations of the other class in both header files which seems to have cleared up a lot of errors, but now the problem is that even with the declarations, when any methods in those classes are called they're not known.
    frown.gif



  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    I had an inlined function in the header which was calling a function of the other class, so I removed this and put it in the .cpp file and now it's compiling fine biggrin.gif

    Nice one Draco, thanks alot.


  • Registered Users Posts: 932 ✭✭✭yossarin


    Jazz it sounds like you need to come into town today for our meeting with Louis


    wink.gif



  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    yeah yeah yeah I'll be there


  • Advertisement
Advertisement