Ammar Samater
Ammar Samater

Reputation: 539

declaring function with an object parameter

I have this code:

#ifndef AI_H
#define AI_H

void BuildTree(Board b);
int getMove();
void acceptMove(int);


#endif

and the cpp file:

#include "AI.h"
#include "Board.h"

void BuildTree(Board b)
{

}

int getMove()
{

    return 0;
}
void acceptMove(int)
{

}

I am getting an error because of the paramater Board b in the header file. the error is:

Error 1 error C2065: 'Board' : undeclared identifier

why is it not accepting an object?? I want the function to receive an object by value, not reference.

Upvotes: 0

Views: 50

Answers (3)

Ayush Gupta
Ayush Gupta

Reputation: 1717

Include Board.h in your first file, AI.h

Upvotes: 1

YSC
YSC

Reputation: 40070

The compiler is complaining about Board: it does not know what is it. You must define (not only declare) it to be able to use an object of that type (e.g. taking it as parameter).

You can solve your issue by #includeing the header file defining Board :

#include "Board.h"

Upvotes: 1

vincentp
vincentp

Reputation: 1433

Just include Board.h in ai.h:

#ifndef AI_H
#define AI_H

#include "Board.h"

void BuildTree(Board b);
int getMove();
void acceptMove(int);

#endif

Upvotes: 2

Related Questions