Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ compilation problems

  • 15-03-2001 03:50AM
    #1
    Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭


    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


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭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



  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭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, Registered Users 2 Posts: 932 ✭✭✭yossarin


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


    wink.gif



  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    yeah yeah yeah I'll be there


  • Advertisement
Advertisement