MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / A

Class A

base_code/static_in_class.cpp:4–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4class A
5{
6private:
7 int a;
8 static int sa;
9public:
10 void show()
11 {
12 cout << "show(): " << sa++ << endl;
13 }
14 static void s_show()
15 {
16 //cout << a << endl; //报错,静态成员函数不能调用非静态成员变量。无法使用this.a
17 cout << "s_show(): " << sa << endl;
18 // show(); //报错,静态成员函数不能调用非静态成员函数。无法使用this.show()
19 }
20};
21int A::sa = 1; //只在定义时可以不受private的限制,可以用类名调用私有成员。其他时候不行
22 //若不赋初值,则默认初始化赋值0
23

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected