C++ 不正确不需要重新声明 class 成员变量 MFC handmade solution/project MS VS 2015
C++ uncorrect not required re-declaring of class member variable MFC handmade solution/project 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;
怎么了?
问题出在成员变量MFC_Tutorial_Window *m_pMainWnd;
的重新声明中,没有这一行它会起作用。
我试图缩短一个外国代码。我想我可以保存一个变量。
下面给出的代码是正确的,并显示了一个 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;
怎么了?
问题出在成员变量MFC_Tutorial_Window *m_pMainWnd;
的重新声明中,没有这一行它会起作用。