是说m_pMainWnd指针是CWinThread类的一个成员变量,这个 成员变量是指向CWnd类对象的指针。 CWinThread::m_pMainWnd 说明m_pMainWnd的作用域,而 m_pMainWnd is a public variable of type CWnd* 则说明类型, 不矛盾!
强制转换在什么了条件下才可以用? : when you want to use but you must kown the type of the memory pointed by the pointerm , kown yourelf not computer. you can up cast a pointer. CWnd* pWnd = pView; but when down cast a pointer your code must be : CView* pView = (CView*) pWnd; and you must be sure the pWnd point to an instence of CView or any Class which parent class is CView.
成员变量是指向CWnd类对象的指针。
CWinThread::m_pMainWnd 说明m_pMainWnd的作用域,而
m_pMainWnd is a public variable of type CWnd* 则说明类型,
不矛盾!
我是初手,
我写了一段简单的代码,运行是正确的,
如下:
CWnd* wnd,* view;
wnd=AfxGetMainWnd();
view=((CMainFrame*)wnd)->GetActiveView();
view->PostMessage(WM_MSG1,0,0);
但我查了MSDN,GetActiveView()返回CView*,但我的view
是CWnd*的,还有强制转换在什么了条件下才可以用,不同的
指针之间都可以无条件转换吗,上面代码有一个转换(CMainFrame*)wnd
: when you want to use
but you must kown the type of the memory pointed by the pointerm , kown yourelf not computer.
you can up cast a pointer.
CWnd* pWnd = pView;
but when down cast a pointer
your code must be :
CView* pView = (CView*) pWnd;
and you must be sure the pWnd point to an instence of CView or any Class
which parent class is CView.
指向基类的指针也可以指向他的派生类,所以CWnd*也可以指向CView
事实上CView*也是CWnd*