我最近再次开始使用 C++ 编程,出于教育目的,我正在开发一款扑克游戏。奇怪的是,我不断收到以下错误:
1>LearningLanguage01.obj : error LNK2019: unresolved external symbol "public: __thiscall PokerGame::Poker::Poker(void)" (??0Poker@PokerGame@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'pokerGame''(void)" (??__EpokerGame@@YAXXZ)
1>LearningLanguage01.obj : error LNK2019: unresolved external symbol "public: __thiscall PokerGame::Poker::~Poker(void)" (??1Poker@PokerGame@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'pokerGame''(void)" (??__FpokerGame@@YAXXZ)
1>LearningLanguage01.obj : error LNK2019: unresolved external symbol "public: void __thiscall PokerGame::Poker::begin(void)" (?begin@Poker@PokerGame@@QAEXXZ) referenced in function _wmain
1>C:\Visual Studio 2012\Projects\LearningLanguage01\Debug\LearningLanguage01.exe : fatal error LNK1120: 3 unresolved externals
我对这个问题做了一些研究,大多数都指向标头中的构造函数和析构函数定义与 .cpp 不匹配。我没有看到标题和 .cpp 有任何问题。
这是 poker.h 的代码:
#pragma once
#include "Deck.h"
using namespace CardDeck;
namespace PokerGame
{
const int MAX_HAND_SIZE = 5;
struct HAND
{
public:
CARD cards[MAX_HAND_SIZE];
};
class Poker
{
public:
Poker(void);
~Poker(void);
HAND drawHand(int gameMode);
void begin();
};
}
.cpp 中的代码:
#include "stdafx.h"
#include "Poker.h"
using namespace PokerGame;
const int TEXAS_HOLDEM = 0;
const int FIVE_CARD = 1;
class Poker
{
private:
Deck deck;
Poker::Poker()
{
deck = Deck();
}
Poker::~Poker()
{
}
void Poker::begin()
{
deck.shuffle();
}
//Draws a hand of cards and returns it to the player
HAND Poker::drawHand(int gameMode)
{
HAND hand;
if(gameMode == TEXAS_HOLDEM)
{
for(int i = 0; i < sizeof(hand.cards); i++)
{
hand.cards[i] = deck.drawCard();
}
}
return hand;
}
};