•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,434 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,322 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2119 | Replies: 2
![]() |
•
•
Join Date: Mar 2005
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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.
I've given this A & B example just to simplify the problem I'm having.
Thanks,
James
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
Another way might be to define two classes with everything private (-constructors) and put the other classes functions as friends? the use of the static keyword could help as static fields dont require objects to be created (they can be used like 'constants' in effect)
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- PCI Simple Communication Controller (Windows NT / 2000 / XP / 2003)
- java and using observable class (Java)
- Class Server query (Windows NT / 2000 / XP / 2003)
- "missing storage-class or type specifiers" error (C++)
- Any experiences with the new Microsoft Live Communication Server (Windows NT / 2000 / XP / 2003)
- would somebody buy this for me? (Troubleshooting Dead Machines)
- first math class in uni (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: Interactive text file
- Next Thread: How to get the cursor position on an image


Linear Mode