得到了LNK2001错误

时间:2014-09-30 16:34:24

标签: c++ oop

我得到3个错误:

错误LNK2001:未解析的外部符号“private:static class std :: basic_string,class std :: allocator> * CDiceGame :: diceInfo”(?diceInfo @ CDiceGame @@ 0PAV?$ basic_string @ DU?$ char_traits @ D @ std @ @V?$ @分配器@ d @@ 2 STD @@ A)

错误LNK2001:未解析的外部符号“private:static class std :: basic_string,class std :: allocator> CDiceGame :: stSide”(?stSide @ CDiceGame @@ 0V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ A)

错误LNK2001:未解析的外部符号“private:static unsigned int CDiceGame :: unMoney”(?unMoney @ CDiceGame @@ 0IA)

这是我的源代码,我只是发布问题发生的部分,其他部分都很好:
CDiceGame.h

#pragma once
#include "CDice.h"

class CDiceGame
{
    static string diceInfo[3];
    static unsigned int unMoney;
    static string stSide;
public:
    static void Bet();
    static unsigned int Play();
};

CDiceGame.cpp

#include "CDiceGame.h"

void CDiceGame::Bet()
{
    cout << "Bet money: ";
    cin >> unMoney;
    cout << "Bet for: ";
    cin >> stSide;
}
unsigned int CDiceGame::Play()
{
    int  i;
    CDice Dice;
    Dice.init("fish", "prawn", "crab", "rooster", "stag", "squash");
    CRand::randomize();
    for (i = 0; i < 3; i++)
        diceInfo[i] = Dice.roll();
    int nCount = 0;
    for (i = 0; i < 3; i++)
        if (diceInfo[i] == stSide)
            nCount++;
    if (nCount > 0)
        return unMoney + (unsigned int)pow(unMoney * 1.0, nCount);
    else
        return 0;
}

主:

#include "CDiceGame.h"

void main()
{
    CRand::randomize();
    CDiceGame::Bet();
    cout << CDiceGame::Play();
    system("pause");
}


如何解决这个错误? (我正在使用MS Visual Studio 2010)

0 个答案:

没有答案