Encapsulation in SDL

Started by
3 comments, last by this_is_phil 15 years, 8 months ago
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();
};


Advertisement
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.
Sorry I just realised that I hadn't flagged the error but I have now.
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.
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.

This topic is closed to new replies.

Advertisement