RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 2244 | Replies: 2
Join Date: Mar 2005
Posts: 9
Reputation: j.kelly is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
j.kelly j.kelly is offline Offline
Newbie Poster

Two-way class communication

  #1  
Mar 20th, 2005
I'm pretty new to C++ and I'm having a problem with a Uni coursework.

I have two classes A & B which need to be able to call each others functions so they each hold a pointer to the other.

I had the problem that they #included each other so I was getting an include recursion, which I solved by using forward referencing.

Now I have the problem that because I used forward referencing when I come to implement a function to use that pointer I am told that the class whose pointer I want to use is not defined.

function implementation:

void A::MyFunction()
{
    this->pointer->MyFunction();
}


headers:

class B;
class A
{
public:
    A(B* aPointer);
    ~A(void);
    void MyFunction();
private:
    B* pointer;
};

class A;
class B
{
public:
    B(A* aPointer);
    ~B(void);
    void MyFunction();
private:
    A* pointer;
};

I've given this A & B example just to simplify the problem I'm having.

Thanks,
James
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:21 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC