Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

C++ global class, unresolved external symbol

When I compile the following it give me a link error:
Error      1      error LNK2001: unresolved external symbol "private: static enum Language i18n::currentLanguage" (?currentLanguage@i18n@@0W4Language@@A)      C:\Users\Public\0SBCS\VS\test\i18ntest\i18ntest\MenuItemONE.obj      i18ntest
My idea is to:
  + 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
  };

Open in new window


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

Open in new window


i18n.cpp
#include "StdAfx.h"
#include "i18n.h"

Open in new window


MenuItemONE.h
#pragma once
#include <string>
#include <iostream>
#include "Language.h"

class MenuItemONE
{
public:
    std::string GetText();
    Language GetCurrentLanguage();
};

Open in new window


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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Language i18n::currentLanguage = ENGLISH;

i should make a refresh more often :-)

Sara