1

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.

3
  • 1
    try to move the Button class definition to the "Button.h" header Commented Dec 18, 2012 at 4:02
  • Are you including the header files in the cpp files? Commented Dec 18, 2012 at 4:04
  • What lines give the errors? Commented Dec 18, 2012 at 4:04

3 Answers 3

1

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[] ); 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

I guess the class should be declared before the function declaration/definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.