-2

I'm new to C++, and I'm trying to use a static member variable as a "dictionary" in a translation program.

I have two files, alphabet.h, which looks like this:

#ifndef ALPHABET_H
#define ALPHABET_H
#include <map>
#include <vector>

class Alphabet {
  public:
    typedef std::vector<std::string> letterType;
    typedef std::map<std::string, letterType> alphabetType;
    alphabetType getAlphabet();
  private:
    static alphabetType m_alphabet;
};

#endif

And alphabet.cpp, which looks like this:

#include "alphabet.h"

static Alphabet::alphabetType m_alphabet = {{"ὁ",{"o"}}};

Alphabet::alphabetType Alphabet::getAlphabet() {
    return Alphabet::m_alphabet;
}

For some reason when I attempt to compile, I get an error from g++.

In function Alphabet::getAlphabet[abi:cxx11]()': alphabet.cpp:6: undefined reference toAlphabet::m_alphabet[abi:cxx11]' collect2: error: ld returned 1 exit status

I would appreciate any insight into what I'm doing wrong.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Larry Turtis
  • 1,907
  • 13
  • 26

1 Answers1

4
static Alphabet::alphabetType m_alphabet = {{"ὁ",{"o"}}};

should be

Alphabet::alphabetType Alphabet::m_alphabet = {{"ὁ",{"o"}}};

Here, you define an other variable.

Jarod42
  • 203,559
  • 14
  • 181
  • 302