继承中的static

继承中的static

1620839824421

1620839885212

1620839891459

1620840002589

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#define  _CRT_SECURE_NO_WARNINGS 
#include <iostream>

using namespace std;

class A
{
public:
static int s;

private:

};

int A::s = 0;//静态成员变量要在类的外部初始化

class B :public A
{
public:
private:
};

int main(void)
{
B b;
cout << b.s << endl;
b.s = 100;
cout << b.s << endl;

cout << A::s << endl;

return 0;
}