CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Enum Question

  1. #1
    Join Date
    Dec 2003
    Posts
    15

    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 "";
    }

  2. #2
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315
    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.

  3. #3
    Join Date
    Dec 2003
    Posts
    15
    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

  4. #4
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    182
    Try this:
    m_LanguageFile.open(m_CSettings->GetSetting(CSettings::LanguagePath), ios:ut);
    Good luck

  5. #5
    Join Date
    Dec 2003
    Posts
    15
    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
  •  





Click Here to Expand Forum to Full Width

Featured