deleyd
asked on
C++ global class, unresolved external symbol
When I compile the following it give me a link error:
+ enumerate the languages
+ store the current language setting in a static class
+ later return a string based on the current language setting
C++ doesn't have static classes, so I'm using a class with static members and static fields. (Any suggested improvements?)
Language.h
i18n.h
i18n.cpp
MenuItemONE.h
MenuitemONE.cpp
Error 1 error LNK2001: unresolved external symbol "private: static enum Language i18n::currentLanguage" (?currentLanguage@i18n@@0WMy idea is to:4Language@ @A) C:\Users\Public\0SBCS\VS\t est\i18nte st\i18ntes t\MenuItem ONE.obj i18ntest
+ enumerate the languages
+ store the current language setting in a static class
+ later return a string based on the current language setting
C++ doesn't have static classes, so I'm using a class with static members and static fields. (Any suggested improvements?)
Language.h
#pragma once
enum Language
{
ENGLISH,
SPANISH,
FRENCH
};
i18n.h
#pragma once
#include "language.h"
class i18n
{
private:
static Language currentLanguage;
public:
static Language GetCurrentLanguage()
{
return currentLanguage;
}
static void SetCurrentLanguage(Language lang)
{
currentLanguage = lang;
}
};
i18n.cpp
#include "StdAfx.h"
#include "i18n.h"
MenuItemONE.h
#pragma once
#include <string>
#include <iostream>
#include "Language.h"
class MenuItemONE
{
public:
std::string GetText();
Language GetCurrentLanguage();
};
MenuitemONE.cpp
#include "StdAfx.h"
#include "MenuItemONE.h"
#include "Language.h"
#include "i18n.h"
Language MenuItemONE::GetCurrentLanguage()
{
return i18n::GetCurrentLanguage();
}
std::string MenuItemONE::GetText()
{
Language cl = GetCurrentLanguage();
switch(cl)
{
case ENGLISH:
default:
return "English ONE menu text";
break;
case SPANISH:
return "Spanish ONE menu text";
break;
case FRENCH:
return "French ONE menu text";
break;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i should make a refresh more often :-)
Sara