-
December 3rd, 2003, 12:22 PM
#1
Enum Question
Howdy All,
Ok, for starters let clear up the fact that I am somewhat new to C++ and this is my first post, so please bear with me.
Using VC++ 6 MFC
I have 2 classes. A languages class and a settings class. When initialized the languages class is passed a pointer to the Settings class. The pointer is then used to retirieve settings values.
When calling the GetSetting function I am trying to pass an enum. This is were the problem arises. When calling the GetSetting function from CLanguages it says that the enum value is an undeclared iedetifier:
error C2065: 'LanguagePath' : undeclared identifier
Thanks In Advance
Jeremy
Code:
class CLanguages
{
private:
fstream m_LanguageFile;
void OpenLanguageFile(bool Output = FALSE);
CSettings* m_CSettings;
public:
CLanguages(CSettings* Settings);
virtual ~CLanguages();
};
void CLanguages::OpenLanguageFile(bool Output)
{
if (!m_LanguageFile.is_open())
{
if (Output)
m_LanguageFile.open(m_CSettings->GetSetting(LanguagePath), ios::out); //Generates error!
else
m_LanguageFile.open(m_CSettings->GetSetting(LanguagePath), ios::in); //Generates error!
}
}
class CSettings
{
private:
struct structSetting
{
CString Setting;
CString Value;
int ID;
};
CArray <structSetting, structSetting> m_Settings ;
bool m_bSettingsLoaded;
void LoadSettings();
public:
enum SettingID
{
LanguagePath,
ResourceMaster
};
CSettings();
virtual ~CSettings();
CString GetSetting(SettingID ID);
};
CString CSettings::GetSetting(SettingID ID)
{
int idx = 0;
if (!m_bSettingsLoaded)
CSettings::LoadSettings();
for ( idx = 0 ; m_Settings.GetSize (); idx++ )
{
if (m_Settings [idx].ID == ID)
return m_Settings [idx].Value;
}
return "";
}
-
December 3rd, 2003, 12:46 PM
#2
I like to put my enum(s) in global scope to avoid these types of problems. You could define your enum in the global scope of settings.h and include settings.h in languages.cpp. This would give you scope of the enum from both classes.
-
December 3rd, 2003, 12:59 PM
#3
Originally posted by sambo
I like to put my enum(s) in global scope to avoid these types of problems. You could define your enum in the global scope of settings.h and include settings.h in languages.cpp. This would give you scope of the enum from both classes.
If I'm not mistaken the enum is already declared global in the Settings class. Adding the #include to the Language class did not help. I received the same error.
Jeremy
-
December 3rd, 2003, 01:04 PM
#4
Try this:
m_LanguageFile.open(m_CSettings->GetSetting(CSettings::LanguagePath), ios:ut);
Good luck
-
December 3rd, 2003, 01:46 PM
#5
Originally posted by Caprice
Try this:
m_LanguageFile.open(m_CSettings->GetSetting(CSettings::LanguagePath), ios: ut);
Thank You Caprice that did the trick.
Jeremy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|