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

  • Home
  • SEARCH
  • 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 8521511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:50:55+00:00 2026-06-11T06:50:55+00:00

im a noob especially in c++. I have some problems using a struct that

  • 0

im a noob especially in c++.

I have some problems using a struct that i want to use in some functions.

I looked at the other answers here regarding structs in Header files and .cpp but dont realy get it to work.

my .h file:

namespace game {

class CPlayer{

        struct GameData{
        int mBoard[8][8];
        CBoard &pBoard;
    };
public:

    CMove Play(const CBoard &pBoard,const CDeadline &pDue);

private:

    int GainsFromMoves(struct GameData gameData);

etc…..

then in my .cc file im trying to use this data with:

CMove CPlayer::Play(const CBoard &pBoard,const CDeadline &pDue)
{

     GameData gameData;

     gameData.pBoard = pBoard;

etc…

where i try to declare the GameData i get an error uninitialized reference member in ‘struct game::CPlayer::GameData’

later trying to usethe GainsFromMoves function i also get some error.

int GainsFromMoves(GameData gameData){

 int test = 0;

 return test;
}

error: Multiple markers at this line
    - expected ‘,’ or ‘;’ before ‘{’ token
    - ‘GameData’ was not declared in this 
     scope

i realize that i probably am doing some really noob error but, i would be very happy for some guidance.

  • 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-06-11T06:50:56+00:00Added an answer on June 11, 2026 at 6:50 am

    OK, first, you need declarations of CMove, CBoard and CDeadline. I added some dummy ones to allow fixing the other problems:

    namespace game {
    
    struct CBoard {};
    struct CDeadline {};
    struct CMove {};
    ...
    

    Then, your struct CPlayer::GameData needs to intialize it’s CBoard reference, which should be const:

    class CPlayer{
    
            struct GameData
            {
              GameData(const CBoard& board) : pBoard(board) {}
              int mBoard[8][8];
              const CBoard &pBoard;
            };
    public:
        CMove Play(const CBoard &pBoard,const CDeadline &pDue);
    private:
        int GainsFromMoves(struct GameData gameData);
    };
    

    Next, in your .cc file, you need the namespace as well as the class name when defining member functions:

    namespace game
    {
    CMove CPlayer::Play(const CBoard &pBoard,const CDeadline &pDue)
    {
         GameData gameData(pBoard);
         return CMove();
    }
    int CPlayer::GainsFromMoves(GameData gameData){
    
      int test = 0;
    
     return test;
    }
    
    } // namespace game
    

    This gets rid of the errors, at least with this simple main:

    int main()
    {
      game::CBoard b;
      game::CDeadline d;
      game::CPlayer p;
      p.Play(b, d);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
PowerShell noob question here. I have groups of servers that are listed in separate
Noob here. I have a rails app that has users and postings. I need
noob Android/JSON person here. I hope someone might help me? I've looked and looked
I have never designed a database/data-model/schema from scratch, especially for a web-application. In some
noob to C# here, using iTextSharp examples from around SO I've made a basic
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
Super noob question here... The file source: www.mysite.com/blah/blah/customdir/ajax/folder/file.php and I want to include a
Emacs noob here, For some reason, when I try to Open a existing C++
noob here, I'm trying to transfer a file using rsync from windows to linux.

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.