У меня вопрос об ошибке, которую я получаю при попытке собрать карточную игру, которую я делаю.У меня есть класс с именем Player, который принимает const char * в качестве параметра для своего конструктора.Я пытаюсь создать 4 экземпляра Player в структуре, называемой GameState, однако она выдает мне эту ошибку.
In file included from testfile.cc:5:0:
gamestate.h:22:17: error: expected identifier before string constant
gamestate.h:22:17: error: expected â,â or â...â before string constant
gamestate.h:23:17: error: expected identifier before string constant
gamestate.h:23:17: error: expected â,â or â...â before string constant
gamestate.h:24:17: error: expected identifier before string constant
gamestate.h:24:17: error: expected â,â or â...â before string constant
gamestate.h:25:18: error: expected identifier before string constant
gamestate.h:25:18: error: expected â,â or â...â before string constant
In file included from player.cc:3:0:
gamestate.h:22:17: error: expected identifier before string constant
gamestate.h:22:17: error: expected â,â or â...â before string constant
gamestate.h:23:17: error: expected identifier before string constant
gamestate.h:23:17: error: expected â,â or â...â before string constant
gamestate.h:24:17: error: expected identifier before string constant
gamestate.h:24:17: error: expected â,â or â...â before string constant
gamestate.h:25:18: error: expected identifier before string constant
gamestate.h:25:18: error: expected â,â or â...â before string constant
In file included from game_functions.cc:3:0:
gamestate.h:22:17: error: expected identifier before string constant
gamestate.h:22:17: error: expected â,â or â...â before string constant
gamestate.h:23:17: error: expected identifier before string constant
gamestate.h:23:17: error: expected â,â or â...â before string constant
gamestate.h:24:17: error: expected identifier before string constant
gamestate.h:24:17: error: expected â,â or â...â before string constant
gamestate.h:25:18: error: expected identifier before string constant
gamestate.h:25:18: error: expected â,â or â...â before string constant
Код для GameState
#ifndef __GAMESTATE_H__
#define __GAMESTATE_H__
#include <gtk/gtk.h>
#include "deck.h"
#include "player.h"
#include "trick.h"
using namespace std;
struct GameState
{
GtkWidget *ai1_hand_image;
GtkWidget *ai2_hand_image;
GtkWidget *ai3_hand_image;
GtkWidget *play_area;
GtkWidget *info_label;
GtkWidget *pass_button;
GtkWidget *play_card_button;
GtkWidget *player_hand;
Player ai1( "ai1" );
Player ai2( "ai2" );
Player ai3( "ai3" );
Player user( "user" );
Deck deck();
Trick current_trick;
int trick_num;
bool hearts_broken;
};
#endif
Файл заголовка для Playeris
#ifndef __PLAYER_H__
#define __PLAYER_H__
class GameState;
#include <vector>
#include "card.h"
using namespace std;
class Player
{
public:
Player( const char *_name );
void add_to_hand( Card _card);
void remove_from_hand( Card _card );
bool hand_contains( Card _card );
void set_valid_cards( GameState *game_state );
vector < Card > get_valid_cards();
const char *get_name();
private:
const char *name;
vector < Card > hand;
vector < Card > valid_cards;
};
#endif
Однако, когда я делаю их Pointers в структуре, это работает нормально.Также работает создание экземпляров Player вне GameState.
Это работает:
Player *ai1;
Player *ai2;
Player *ai3;
Player *user;
, и это, когда он находится в testfile.cc:
Player user( "user" );
Может кто-нибудьскажите мне, почему я получаю эти ошибки, когда создаю их внутри GameState.Большое спасибо, ребята!