#include
#include
using namespace std;
class Base
{
public:
static void func()
{
cout << "Base-static void func()" << endl;
}
static void func(int a)
{
cout << "Base-static void func(int a)" << endl;
}
static int m_A;
};
int Base::m_A = 100;
class Son :public Base
{
public:
static void func()
{
cout << "Son-static void func()" << endl;
}
static int m_A;
};
int Son::m_A = 200;
void test01()
{
cout << "通过对象访问" << endl;
Son s;
cout << s.m_A << endl;
cout << s.Base::m_A << endl;
cout << "通过类名访问" << endl;
cout << Son::m_A << endl;
cout << Son::Base::m_A << endl;
}
void test02()
{
cout << "通过对象访问" << endl;
Son s;
s.func();
s.Base::func();
cout << "通过类名访问" << endl;
Son::func();
Son::Base::func();
Son::Base::func(100);
}
int main()
{
test01();
test02();
return 0;
}
- 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
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65