Hello,
I require a help on a basic issue.
I have 2 classes and I want to have an interaction among the classes.
Suppose my 2 classes are testA and testB. Now I want a handle of object pointer in each class to the other class. Like I want a variable in testA to be testB* t and a variable in testB to be testA* t.
How can I implement this situation???
I have included the code for easy understanding. This code doesn't work since it is not able to resolve the declarations.
Your help is highly appreciated!!!
I don't think it will solve the problem.
Check the output:
testA.C:26: error: invalid use of undefined type ‘struct TestB’
testA.C:3: error: forward declaration of ‘struct TestB’
testA.C: In member function ‘void TestB::test()’:
testA.C:27: error: invalid use of undefined type ‘struct TestB’
testA.C:3: error: forward declaration of ‘struct TestB’
testA.C:27: error: ‘b’ was not declared in this scope
Thanks very much!!!
I need a little more help.
If I want to place testA.C and testB.C in separate files then how to do it???
Like the following:
testA.C should look like:
Well the classes themselves go in
TestA.h and TestB.h
The actual implementations go in
TestA.cpp and TestB.cpp
Further, when you do something like
b->id
within an 'A' member function, you should really use something like
b->getID()
so that later on, when you make all the data private, your code will still work.
Thanks a lot!!!
I think I am not considering dependencies.
OK..Now I am able to compile testA.C
But then how to compile testB.C
g++ -c testB.C gives error now!!!
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.