// 1、如果子类中不再定义一个静态成员,那么父类和子类公用一个静态成员a;
// 如果子类中有定义了一遍,那么各用各的,互不影响。
// 2、非静态成员,子类不会继承父类的成员值。
// 3、注意:C++中,静态成员函数不能被声明为virtual函数
#include <iostream>
using namespace std;
class Base
{
public:
static int a;
void say()
{
//cout << "Base:"<<a << endl;
cout << "Base:" << b << endl;
}
int b;
};
class Son : public Base
{
public:
void show()
{
//cout << "Son:"<<a << endl;
cout << "Son:" << b << endl;
}
static int a;
};
int Son::a = 20;
int Base::a = 10;
int main()
{
Base b;
b.say();
Son s;
s.show();
b.b = 11;
b.say();
s.show();
s.b = 21;
b.say();
s.show();
return 0;
}