Reputation: 13
I'm a bit new to programming and ran into these errors tracing to the function prototype in the function header file and I think it may have something to do with the array of pointers it's getting.
error variable or field 'clean_up' declared void
error 'Button' was not declared in this scope
error 'buttons' was not declared in this scope
error expected primary variable before ']' token
//Function.h
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#include "functions.h"
#include "globals.h"
#include "Button.h"
#include <fstream>
void clean_up( Button *buttons[] ); // errors here
//Function.cpp
void clean_up( Button *buttons[] )
{
SDL_FreeSurface( background );
SDL_FreeSurface( X );
SDL_FreeSurface( O );
for( int t = 0; t < TOTAL_BUTTONS; t++ )
{
delete buttons[ t ];
}
SDL_Quit();
}
//Button.h
class Button
{
private:
SDL_Rect box;
SDL_Surface *sprite;
public:
bool in_use;
bool xoro;
int p_id;
Button( int x, int y, int id );
~Button();
void handle_events();
void show();
};
//Button.cpp
Button::Button( int x, int y, int id )
{
box.x = x;
box.y = y;
box.w = 120;
box.h = 120;
in_use = false;
p_id = id;
}
Button::~Button()
{
SDL_FreeSurface( sprite );
}
I wasn't really sure where to look for a solution so any help is appreciated. Thanks.
Upvotes: 1
Views: 514
Reputation:
I guess the class should be declared before the function declaration/definition.
Upvotes: 0
Reputation: 3247
Try adding forward declaration of class Button in the .h file.
Function.h
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#include "functions.h"
#include "globals.h"
#include "Button.h"
#include <fstream>
class Button;
void clean_up( Button *buttons[] );
Upvotes: 1
Reputation: 275500
Function.h includes too many header files. It only depends on Button.
So only include Button.h. or even better, just forward declare class Button;
This will remove the problem in function.h, but it probably the will pop up elsewhere.
As a psychic guess, you are missing a ; or a } somewhere.
Upvotes: 0