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!!!
#include <stdio.h>
class TestA {
public:
TestA();
int id;
TestB* b;
void testPrint();
void test();
void set(TestB* t);
};
void TestA::testPrint() {
printf("I am in class TestA\n");
}
TestA::TestA() {
id = 1;
}
void TestA::set(TestB* t) {
b = t;
}
void TestB::test() {
printf("My ID is: %d and the other ID is: %d\n", this->id, b->id);
}
class TestB {
public:
TestB();
TestA* a;
int id;
void testPrint();
void test();
void set(TestA* t);
};
void TestB::testPrint() {
printf("I am in class TestB\n");
}
TestB::TestB() {
id = 2;
}
void TestB::set(TestA* t) {
a = t;
}
void TestB::test() {
printf("My ID is: %d and the other ID is: %d\n", this->id, a->id);
}