0

So I am trying to make a chess game ( bit of an ultimate challenge for me ), and I'm a stump for this part ..

So I made a piece object, and the idea is that in the main game code, I have an array of pieces and I pass the address of the array to the function "InitilisePieces" and the team ( Black or White ) and it shall assign all the pieces. So I made the function a friend to access all the private members and it comes up with an error saying "inaccessible", and I don't understand what's wrong with doing as I've done. Any help would be more than appreciated!

Side Note: things like State_ and _Location and structs and enums that are defined properly etc, not the problem ... ( I don't think )

Header File Contains:

class   __Piece
{
private:

    State_              e_state;
    Piece_Type_         e_type;
    Team_               e_team;
    _Location           st_location;

    friend void         InitilisePieces     ( __Piece(*)[16], Team_);

public:
    __Piece             ();

};

.cpp File Contains:

void                    InitilisePieces     ( __Piece * pao_piece[16], Team_ )
{
    int         n_count;

    for ( n_count = 0; n_count < 16; n_count++ )
    {
        pao_piece[ n_count ]->e_state;
    }
}

UPDATE:

Thankyou for the explanations and I get where I'm going wrong now ... so what is the parameter supposed to be to pass the address of an array of __Piece 's?

user3502489
  • 361
  • 1
  • 4
  • 11

1 Answers1

7

Your friend function and the function you define later have the same name but different signatures. You have not defined the friend function.

This

void InitilisePieces( __Piece(*)[16], Team_);

is not the same as this

void InitilisePieces( __Piece * pao_piece[16], Team_ )

The former's first parameter is a pointer to an array of 16 __Pieces. The latter's first parameter is adjusted to __Piece** pao_piece, i.e a pointer to a pointer to a __Piece. In other words, it is this:

void InitilisePieces( __Piece** pao_piece, Team_ )

Also: watch out for reserved identifiers.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480