Static variables in classes don't work the same as static variables in C. A static variable in C++, declared as a class member, means that it is shared amongst all instances of the class.
Perhaps a better idea:
Code:
class Dog {
protected:
int array[2];
public:
inline void print_array() {
cout << array[0] << endl << array[1] << endl;
}
};
class Collie : public Dog {
public:
Collie() { // override constructor
array[0] = 5;
array[1] = 6;
}
};
class Spaniel : public Dog {
public:
Spaniel() {
array[0] = 7;
array[1] = 8;
}
};
int main() {
Collie c;
Spaniel s;
c.print_array();
s.print_array();
return 0;
}
I'm still not really sure what your code even attempts to do, but hopefully that helps.