// 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;
}