// 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);
//基類(lèi)子類(lèi)的this指針相同,但在這里this->a,this->b里的a,b都是基類(lèi)的成員變量,不過(guò)基類(lèi)和子類(lèi)共用一個(gè)b
//成員,所以b 是在子類(lèi)里改過(guò)的。
//父類(lèi)中任何成員函數(shù)體內(nèi)直接調(diào)用的函數(shù),絕不可能是子類(lèi)的。
}
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;
}