I am trying to access a variable which is inside of an object (TestClassThree.h) which is inside the parent class (TestClassOne.h). Each class is in its own file, and when I try to import the files to instantiate the classes it crashes. I suspect it is because of import loops. I don't think that I can use forward class declarations, because that would restrict the access to the variable. How can I access the variable inside of TestClassThree from TestClassTwo?
//--TestClassOne.h--
#include "TestClassTwo.h"
#include "TestClassThree.h"
class TestClassOne {
public:
TestClassTwo *myVariable;
TestClassThree *mySecondVariable;
TestClassOne() {
myVariable = new TestClassTwo(this);
mySecondVariable = new TestClassThree();
}
};
//--TestClassTwo.h--
#include "TestClassOne.h" //<-- ERROR
class TestClassTwo {
public:
TestClassOne *parent;
TestClassTwo(TestClassOne *_parent) : parent(_parent) {
}
void setValue() {
parent->mySecondVariable->mySecondVariable->value = 10;
}
};