程序工作正常,但內存驗證程序報告錯誤未初始化讀線CProfiles配置文件;類初始化問題
CProfiles外部的CProfiles類的「配置文件」定義是不好的編程習慣嗎?
這裏是我的代碼: 內profiles.cpp
#include "profiles.h"
CProfiles profile; // Here it reports the problem
KeyProfile* keyProfile=&profile; // keyProfile is later used in other classes
//-------------------------------------------------------------
CProfiles::CProfiles():forceDialog(0)
{
oldName="";
}
int CProfiles::Init()
{
_chdir(PROFILES_PATH);
}
CProfiles::~CProfiles()
{
}
內profiles.h
#define PROFILES_PATH "Profiles"
#include "KeyProfile.h"
class CProfiles: public KeyProfile
{
public:
CProfiles();
~CProfiles();
int Init();
bool forceDialog;
string oldName;
};
extern CProfiles profile;
KeyProfile.h
public:
virtual UINT GetKeyUp() { return DIK_UP; }
virtual UINT GetKeyDown() { return DIK_DOWN; }
virtual UINT GetKeyLeft() { return DIK_LEFT; }
virtual UINT GetKeyRight() { return DIK_RIGHT; }
virtual UINT GetKeyAction() { return DIK_RETURN; }
virtual UINT GetKeyCancel() { return DIK_RCONTROL; }
virtual UINT GetKeyEsc() { return DIK_ESCAPE; }
KeyProfile(void){};
virtual ~KeyProfile(void){};
};
extern KeyProfile* keyProfile;
向我們展示'KeyProfile :: KeyProfile()'(以及繼承鏈中的其他相關構造函數)。 – NPE
class KeyProfile { public: \t virtual UINT GetKeyUp()\t \t {return DIK_UP; } \t virtual UINT GetKeyDown()\t {return DIK_DOWN; } \t virtual UINT GetKeyLeft()\t {return DIK_LEFT; } \t virtual UINT GetKeyRight()\t {return DIK_RIGHT; } \t virtual UINT GetKeyAction()\t {return DIK_RETURN; } \t virtual UINT GetKeyCancel()\t {return DIK_RCONTROL; } virtual UINT GetKeyEsc()\t {return DIK_ESCAPE; } \t KeyProfile(void){}; \t virtual〜KeyProfile(void){}; }; – en667
對不起。已更新爲原始帖子。 KeyProfile.cpp爲空。沒有找到其他相關的構造函數。 – en667