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.
OK, first, you need declarations of
CMove,CBoardandCDeadline. I added some dummy ones to allow fixing the other problems:Then, your struct
CPlayer::GameDataneeds to intialize it’sCBoardreference, which should beconst:Next, in your
.ccfile, you need the namespace as well as the class name when defining member functions:This gets rid of the errors, at least with this simple main: