Hey everybody,
I'm a long-time programmer, but taking my first steps at C++. I have a problem with class declaration in a project with mine.
I have two classes, class1 and class2. Both are instantiated, into variables iClass1 and iClass2 respectively. The problem is that the methods of each class references the variable of the other class, so something like...
1 2 3 4 5 6 7 8 9
|
class1
{
public:
int variable;
int increment()
{
iClass2.variable ++;
}
};
|
1 2 3 4 5 6 7 8 9
|
class2
{
public:
int variable;
int increment()
{
iClass1.variable ++;
}
};
|
Because of this, I cannot find a place to declare the variables. I can't declare before the classes are written, as the compiler is still procedural and can't instantiate undefined classes. I can't declare after the classes are written, as the compiler can't compile classes with undefined variables.
I tried searching online, but surprisingly found no clear-cut answer for what I imagine is a common problem for anyone using more than 2 classes. I talked an expert friend (yes, I read the sticky before posting :D ), and he told me that I would have to pre-declare the variables, slotting empty memory-space into them, and THEN fill them with classes later.
But I have NO idea how to do that. So without further adieu, I open my mind to your advice and critique :)
With humble gratitude,
Catt