您的位置:首页 > 其它

虚函数背后的秘密2

2012-07-19 19:05 274 查看
#include <iostream>

using namespace std;

class Base

{

public:

Base()

{

cout << "In Base" << endl;

cout << "This Pointer = " << (int*) this << endl;

cout << endl;

}

virtual void f()

{

cout << "Base::f" << endl;

}

};

class Drive: public Base

{

public:

Drive()

{

cout << "In Drive" << endl;

cout << "This Pointer = " << (int*) this << endl;

cout << endl;

}

virtual void f()

{

cout << "Drive::f" << endl;

}

};

int main()

{

Drive d;

cout << "In Main" << endl;

cout << "In Main = " << (int*) &d << endl;

return 0;

}

In Base

This Pointer = 0xbfffe47c

In Drive

This Pointer = 0xbfffe47c

In Main

In Main = 0xbfffe47c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: