I've got a problem understanding inheritance.
#include <iostream.h>
class A
{
public:
int x;
};
class S1: public A
{
public:
int x;
};
class S2: public S1
{
public:
int x;
};
int main()
{
S2 obj;
cout << obj.x;
return 0;
}
In the code above, I basically want to use all the x's. but, obj.x will only allow me to use the x of class S2. How can I use the x of S1 and A (i) inside the class (ii) outside the class using an object of S2.
Also, while using static variables, how do we initialize them outside the class?
Is it like this?
class A
{
public:
static int x;
};
A::x = 10;