我正在做一个涉及卡片游戏课程的项目,可以玩Go Fish或Poker。但是,当我尝试编译文件时,我在{“错误之前收到了”预期的类名。我将仅包含Go Fish界面以避免读者麻烦。下面是我试图编译的代码。
//card_games.h
#ifndef CARD_GAMES
#define CARD_GAMES
#include "go_fish.h"
#include "poker.h"
#include "player.h"
#include "deck.h"
class card_games{
public:
card_games();
void checkplayer(char thePlayer);
void convert(char);
void distribute();
void givecard();
void printhand();
~card_games();
protected:
int num_player; //number of players
int player_num; //player's turn
private:
go_fish fishing; //gofish object
poker gamble; //poker object
deck pool; //pool object
player* p; //array of players
};
#endif
//go_fish.h
#ifndef GO_FISH
#define GO_FISH
#include "player.h"
#include "deck.h"
#include "card_games.h"
class go_fish: public card_games{ *//error occurs here*
public:
void startgame(int &player_num);
void checkrank(char&);
void hunt_card(int, int);
void choose(char&);
void checktarget();
void gofish();
void stalemate();
void victory();
void swapturns();
player getplayer(int);
~go_fish(){};
protected:
private:
int decision;
int target;
char choice;
};
#endif
//deck.h
#ifndef DECK
#define DECK
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "card.h"
using namespace std;
class deck{
public:
deck();
card getd(int); //accesor
vector <card> getdeck();
void setcard(int, int, int);
void assign();
void assignrank();
void shuffle();
void printdeck();
void remove_top(int &deck_index);
void remove_topcard(int);
void deck_size();
int getdsize();
~deck();
protected:
private:
vector <card> d;
};
#endif
//player.h
#ifndef PLAYER
#define PLAYER
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "card.h"
using std::vector;
class player{
public:
card getHand(int); //accesors
vector <card> gethand();
void printhand();
int gethandsize();
bool checkdecision(int* decision);
bool compare(int decision, player& thief);
void steal(card);
void discard(int decision);
protected:
private:
vector <card> h;
};
#endif
对任何缩进头痛道歉。
答案 0 :(得分:1)
上述评论中的解释暗示go_fish
不应继承card_games
。如果有的话,也许card_games
可以继承go_fish
和poker
,但可能不会。 card_games
类很可能只是使用聚合(例如has-a relationship)而不是继承。不知道整个设计,我的想法可能与意图不一致。请检查设计并做出决定。可以把它想象成第一次尝试是迭代零,下一次尝试是迭代一次,然后是迭代二次等等。