Sign in to follow this  
this_is_phil

Encapsulation in SDL

Recommended Posts

this_is_phil    100
I am trying to learn SDL with C++, however I am a bit of a noob when it comes to C++ having only recently migrated there from Java and C#, and given my background I have a bit of a fetish for doing things OO. I am trying to create a class to manage the setup and drawing in SDL. I am having trouble though as the compiler (GCC compiler with Code::Blocks) spits out an error when I try to use an SDL_Surface pointer as a return value for a member function. I may be doing something wrong with C++ but as far as I can tell my code is alright. Here is the class declaration:
class SDL_Manager
{
    int _screen_width;
    int _screen_height;
    int _screen_bpp;

public:

    // A pointer to the screen
    SDL_Surface *_screen;

    // Constructor which takes the width, height and bit depth of the screen.
    // 640 x 480 x 32 is the default.
    SDL_Manager(int screen_width = 640, int screen_height = 480, int screen_bpp = 32);

    // The image loading function
    SDL_Surface *load_image(string filename); // On this line it gives me the error "expected ';' before '(' token"
    // The drawing function
    void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination);
    // The initialization function
    bool init();
};


Share this post


Link to post
Share on other sites
stonemetal    288
I am going to go with make that a std::string instead of just string. You probably also need to add #include <string>. In c++ when you put something in a namespace (like they do with the standard library) you must always qualify the name. so it is std::string not just string.

Share this post


Link to post
Share on other sites
Morrandir    304
Quote:
Original post by this_is_phil
I am trying to learn SDL with C++, however I am a bit of a noob when it comes to C++ having only recently migrated there from Java and C#, and given my background I have a bit of a fetish for doing things OO. I am trying to create a class to manage the setup and drawing in SDL.


This sounds like you are just going to wrap up all the SDL functions in one class and call it OO. If that's the case than this has nothing to do with OO.

Quote:

I am having trouble though as the compiler (GCC compiler with Code::Blocks) spits out an error when I try to use an SDL_Surface pointer as a return value for a member function. I may be doing something wrong with C++ but as far as I can tell my code is alright.


Please post the error message and the part of the code the error points to.

EDIT: Too slow. My first guess is std::string as well.

Share this post


Link to post
Share on other sites
this_is_phil    100
Quote:
Original post by Morrandir
EDIT: Too slow. My first guess is std::string as well.


That solved that problem, thanks.

Quote:
Original post by Morrandir
This sounds like you are just going to wrap up all the SDL functions in one class and call it OO. If that's the case than this has nothing to do with OO.

EDIT: Too slow. My first guess is std::string as well.


And I can live with mis-using terminology ;P.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this