结合网上的一些资料,通过自己的一番摸索,得出了一点个人见解。现在写下来,希望与各位同学共同探讨,共同进步。
以下所有代码均是在VS2012下测试。
一个普通的基类
#include <iostream>
namespace std;
3:
class Base
5: {
public:
7: Base():
8: i(0)
9: {
10: }
void test(){
<< i << endl;
13: }
void virtualTest()
15: {
<< i << endl;
17: }
void staticTest()
19: {
<< endl;
21: }
22:
23:
24:
private:
int i;
27:
28: };
29:
int main()
31: {
32: Base b;
33: b.test();
34: b.virtualTest();
35: Base::staticTest();
36:
return 0;
38: }