0
Writing a class that has an array with variables and all sub-classes have values for same array
I am still learning c++ and I couldn't exactly think up the right title for this. But, I want to create a class with an array or function with 3 variables and then create sub-classes that just give those variables a value (with every sub-class having different values).
2 Réponses
+ 1
adel I show you how to do with variables, you try it with array.
#include <iostream>
using namespace std;
class A{
public:
int x = 1;
int y = 2;
int z = 3;
};
class B:public A{
public:
int x = 8;
int y = 9;
int z = 10;
};
int main() {
A a;
B b;
cout << a.y << endl;
cout << b.y << endl;
return 0;
}
Output is 2 and 9.
+ 1
study inheritance