// ttttest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class Base
{
public:
Base()
{
a = 10;
b = 9;
}
virtual void Cry()
{
Shout();
}
void Shout()
{
printf("%d%d",a,b);
printf("%d%d",this->a,this->b);
//基类子类的this指针相同,但在这里this->a,this->b里的a,b都是基类的成员变量,不过基类和子类共用一个b
//成员,所以b 是在子类里改过的。
//父类中任何成员函数体内直接调用的函数,绝不可能是子类的。
}
protected:
int a;
int b;
private:
};
class Derived:public Base
{
public:
int a;
Derived()
{
a = 11;
b = 12;
}
void Cry()
{
printf("%d%d",this->a,this->b);
Shout();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Base * p = new Derived;
p->Cry();
delete p;
return 0;
}