| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1017 人关注过本帖
标题:简单的例子,不明白的问题.请指点...........
只看楼主 加入收藏
wince
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-5-16
收藏
得分:0 

这个程序我又改了一下.
#include <iostream>
#include <typeinfo>
using namespace std;

class CWinApp
{
public:
CWinApp *m_pCurrentWinApp;
public:
CWinApp() { m_pCurrentWinApp = this;
cout <<"CWinApp Constructor"<<endl;}
~CWinApp() {cout <<"CWinApp Destructor"<<endl;}
virtual bool InitInstance() {cout <<"CWinApp::InitInstance"<<endl;return true;}
};

class CMyWinApp : public CWinApp
{
public:
CMyWinApp() {cout <<"CMyWinApp Constructor"<<endl;}
~CMyWinApp() {cout <<"CMyWinApp Destructor"<<endl;}
virtual bool InitInstance() {cout <<"CMyWinApp::InitInstance"<<endl;return true;}

};


int _tmain(int argc, _TCHAR* argv[])
{
CMyWinApp theApp;
cout <<typeid(*theApp.m_pCurrentWinApp).name()<<endl;
return 0;
}
cout <<typeid(*theApp.m_pCurrentWinApp).name()
这条语句输出的是class CMyWinApp 类型.
theApp.m_pCurrentWinApp 是一个CWinApp类型指针
在什么时候theApp.m_pCurrentWinApp指针,指向了CMyWinApp类型呢?

2006-06-13 16:48
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 

语句CMyWinApp theApp中构造CMyWinApp对象时,会调用它的基类CWinApp的构造函数CWinApp(),函数中m_pCurrentWinApp = this;语句就将CMyWinApp对象的地址给了m_pCurrentWinApp指针


世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-06-13 17:02
wince
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-5-16
收藏
得分:0 

明白了.

2006-06-13 17:07
快速回复:简单的例子,不明白的问题.请指点...........
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011476 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved