0
我試圖縮短外國代碼。我認爲我可以保存一個變量。C++不正確不需要重新聲明類成員變量MFC手工解決方案/項目MS VS 2015
以下給出的代碼是確定的,並顯示一個Windows框架。
#include <afxwin.h>
// from source: http://www.codersource.net/2010/01/30/mfc-tutorial-part-1/
class MFC_Tutorial_Window :public CFrameWnd
{
public:
MFC_Tutorial_Window()
{
Create(NULL, "MFC Tutorial Part 1 CoderSource Window");
}
};
class MyApp :public CWinApp
{
MFC_Tutorial_Window *wnd;
public:
BOOL InitInstance()
{
wnd = new MFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
MyApp theApp;
經過我的改名後,它不再起作用。沒有生成錯誤。但它沒有顯示一個框架。
#include <afxwin.h>
// from source: http://www.codersource.net/2010/01/30/mfc-tutorial-part-1/
// and changed by me
class MFC_Tutorial_Window :public CFrameWnd
{
public:
MFC_Tutorial_Window()
{
Create(NULL, "MFC Tutorial Part 1 CoderSource Window");
}
};
class MyApp :public CWinApp
{
// del MFC_Tutorial_Window *wnd;
MFC_Tutorial_Window *m_pMainWnd; // ins
public:
BOOL InitInstance()
{
// del wnd = new MFC_Tutorial_Window();
// del m_pMainWnd = wnd;
m_pMainWnd = new MFC_Tutorial_Window(); // ins
m_pMainWnd->ShowWindow(1);
return 1;
}
};
MyApp theApp;
這是怎麼回事?
你不重新聲明變量'm_pMainWnd'?我不能在第一個代碼中看到它的聲明,那麼爲什麼在第二個例子中創建成員變量'm_pMainWnd'?試着刪除行'MFC_Tutorial_Window * m_pMainWnd;' –
現在它工作。謝謝你的提示。現在我可以理解這種行爲。 – CarpeDiemKopi
Np隊友,很高興幫助。只是發佈它的意見,所以你可以標記這個線程作爲回答,問候:) –