2014-05-10 84 views
0

我正在做一个家庭作业问题,我们必须使用继承。 (我还没有很好的继承)。我们要制作一个父类“card_games”,它有两个子类“gofish”和“poker”。我们获得了我们主要关注的模板,其余设计由我们决定。这里是我的头文件(称为“classes.h”)错误LNK2001继承问题

#include <vector> 

using namespace std; 

struct cards{ 
    int rank; 
    char suit; 
}; 

class players{ 
    public: 
    int points; 
    int active; 
    vector<cards> cardhand; 
    void printhand(players *gameplayers, int person); 
}; 

class card_games{ 
    protected: 
    players *gameplayers; 
    void player_make(); 
    public: 
    virtual void play(); 
}; 


class poker :public card_games{ 
    public: 
    void play(); 
}; 


class gofish :public card_games{ 
    public: 
void play(); 
    }; 





void player0_play(players *gameplayers, cards *cardlist, int people); 
void createdeck(cards *cardlist); 
void shuffle(cards *cardlist); 
void deal(cards *cardlist, int people, players *gameplayers); 
int getplayers(); 

我已经确定了错误的东西与我的虚拟呼叫。错误具体为:

cardgames_play.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall card_games::play(void)" ([email protected][email protected]@UAEXXZ) 

,我相信这会导致我的下一个错误:

card_games.exe : fatal error LNK1120: 1 unresolved externals 

反正东西是错误与我的虚拟无效的功能。 这里是我的主要功能:

#include <iostream> 
#include "classes.h" 



int main(){ 
    card_games *game; 
    int opt; 
    game = NULL; 
    cout << "Poker 1, Go Fish 2" << endl; 
    cin >> opt; 
    if (opt == 1) 
    game = new poker; 
    else if (opt == 2) 
    game = new gofish; 
    game->play(); 

    return 0; 
} 

我们都应该大致使用此模板。如果我理解正确,我创建一个名为game的Card_game类的实例,然后将游戏分配给gofish或poker的实例。然后我将“游戏”解除引用到“play();”功能。我的代码的其余部分,我有一个

void gofish::play(){ blah blah }

void poker::play(){ 
blah blah 
} 

其中有我的代码,工程的其余部分。

有关此错误的任何帮助,非常感谢。谢谢!

P.S.我在Windows 8上使用visual studio 2013.

+0

要么让card_games ::玩(在声明= 0)纯虚或给它一个体({})在声明 – cup

+0

始终是务必阅读时出现的说明选择标签! – Charles

回答

1

方法void play(); in card_games没有body,并且它不是纯虚拟的。只是做了改变:

class card_games{ 
protected: 
    players *gameplayers; 
    void player_make(); 
public: 
    virtual void play()=0; //make it pure virtual 
}; 
+0

非常感谢! – Gigaxalus

+0

@ user2951303, 如果这个或任何答案已经解决了您的问题,请点击复选标记,考虑 [接受它](http://meta.stackexchange.com/q/5234/179419)。 这表示您已经找到了解决方案,并向回答者和您自己提供了一些名誉。没有义务这样做。 – Rakib