I have a difficulty I need help to overcome. I am developing a program that uses more than 1 class. Variables defined in one class are used in other classes. For example:
class X1 {
private:
int a;
int b;
public;
X1() {
a = 10;
b = 20;
}
};
class X2 {
private:
int c;
int d;
public;
X2() {
c = 5 + 2*a;
d = 10 - 4*b;
}
};
int main() {
X2 Test;
int e = 40 + 10*d;
cout << e << endl;
keep_window_open();
return 0;
}
I get a compile error that variable a and b in class X2 are not declared and initialized. I tried making X2 a sub-class of X1, hoping that X2 would inherit the variables a and b, but IO got even more compile errors.
My question: Is there a way to link the classes so that the variables of a prior class are known and usable in the subsequent classes? Or will I have to make one HUGE class?
Thanks in advance.