Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:42:58+00:00 2026-05-27T05:42:58+00:00

I have a question about an error I’m getting when trying to compile a

  • 0

I have a question about an error I’m getting when trying to compile a card game I am making.
I have a class named Player which takes a const char* as a parameter for it’s constructor.
I am trying to create 4 instances of Player in a struct called GameState however it is giving me this error.

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

The code for GameState is

#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

The header file for Player is

#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

However when I make them Pointers in the struct it works fine. Also creating instances of Player outside of GameState also works.

This works:

Player *ai1;
Player *ai2;
Player *ai3;
Player *user;

and this when it is in testfile.cc:

Player user( "user" );

Can anyone tell me why I get those errors when I create them inside GameState.
Thanks alot guys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:42:59+00:00Added an answer on May 27, 2026 at 5:42 am

    You can’t declare objects inside a class (or struct) definition. You have to do it in a function.

    Either use a special function that initializes the objects, or better yet have a constructor do it (in C++ a struct is just a special class where all members are public by default):

    struct GameState
    {
        Gamestate()
            : ai1( "ai1" ), ai2( "ai2" ), ai3( "ai3" ), user( "user" ), deck()
            { }
    
        // The other fields...
    
        Player ai1;
        Player ai2;
        Player ai3;
        Player ai4;
        Player user;
        Deck deck;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about PHP Class. I am trying to get the result
I have a question about tables in MySQL. I'm currently making a website where
I have question about my code which does the Hoare Partition Method. Here is
I have a question about Clozure CL. While I was trying to quickload a
I have a random question about const correctness. Lets say i have a class
I have a question about the following exception I received trying to complete a
I have a question about error/exception handling on the iPhone. I've read the documentation
I have a question about this error and hope someone has ran into it
Little question about Ruby error handling. I have some code that roughly resembles the
I read this question about the error that I'm getting and I learned that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.