C ++头文件和类文件 - 未定义的引用

时间:2012-10-26 20:19:54

标签: c++ qt class header

  

可能重复:
  What is an undefined reference/unresolved external symbol error and how do I fix it?

·H:

class ArithmeticCoding
{
public:
    ArithmeticCoding();
    static void test(QString text);

    static QMap<QChar,int> letters_freq;
}

的.cpp:

QMap<QChar, int> letters_freq;

ArithmeticCoding::ArithmeticCoding()
{
}

void ArithmeticCoding::test(QString text)
{
    for(int i=0; i<text.length(); i++) letters_freq[text.at(i)]++;
}

我正在

  

arithmeticcoding.cpp:-1:错误:未定义引用   `ArithmeticCoding :: letters_freq'

为什么?

1 个答案:

答案 0 :(得分:4)

将其添加到您的一个CPP中

 QMap<QChar,int> ArithmeticCoding::letters_freq;