私が作成しているカードゲームをコンパイルしようとするとエラーが表示されます。 私はPlayerという名前のクラスを持っています。このクラスはコンストラクタのパラメータとしてconst char *をとります。 GameStateと呼ばれる構造体にPlayerのインスタンスを4つ作成しようとしていますが、このエラーが表示されます。カスタムクラスのインスタンスが構造体内で動作しませんが、外部で動作します
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のコードPlayerの
#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
ヘッダファイルには、しかし、私は彼らはそれが正常に動作し、構造体にポインタを作るとき
#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
です。また、GameState以外のPlayerのインスタンスを作成することもできます。
これは動作します:
Player *ai1;
Player *ai2;
Player *ai3;
Player *user;
と、このことはtestfile.ccのとき:私はGameState内でそれらを作成したとき、私はこれらのエラーを取得する理由
Player user("user");
誰も教えてもらえます。 ありがとうたくさんの男!
カードがどのように見て? gamestate.hが直接的または間接的に含まれていると、困ったことになります。 – Ylisar
FWIWでは、C++ 11のクラス定義で初期化できます。 –