I want to put an SDL_Surface into a struct

Started by
2 comments, last by lollan 15 years, 9 months ago
Here's my struct. Theres more in it but i'm only posting relevant code. This is in classes.h

struct thing
{
     thing()
     {};

     thing(SDL_Surface image)
     {
          this->image = image;
     }

     SDL_Surface image;
}
Here's my object I want to create. This is in things.h.

thing tree1(tree);
The sdl_surface doesn't need to point to an image yet, I just want it to be named and in memory so I can use it for something else. When I try and compile this I get this error.

error C2065: 'tree' : undeclared identifier
Now obviously i'm doing something wrong but I don't know what. I have sdl and sdl_image included in both files and I have classes.h included in things.h. Is what i'm trying to do even possible?
Advertisement
SDL_Surface should only ever be handled as a pointer, since it's designed to be reference counted. Copying it by value can cause some bad things to happen, so don't do that.

struct thing{    thing()    {        this->image = NULL;    };    // Note the use of pointers.  Also be sure to    // call SDL_FreeSurface(image) when you're done.    thing(SDL_Surface *image)    {        this->image = image;    }    SDL_Surface *image;}



However, that's not what's causing the compiler error here. Your problem is that "thing tree1(tree);" is interpreting 'tree' as a type name, and you have not defined this before referring to it.
Quote:
However, that's not what's causing the compiler error here. Your problem is that "thing tree1(tree);" is interpreting 'tree' as a type name, and you have not defined this before referring to it.


Why is it doing that? Isn't SDL_Surface the type name? What am I supposed to be defining?
Hi,

How have you declared : tree ?
Chances are that you didn't declare it correctly, besides you should take the advice of hh10k about using pointer.

This topic is closed to new replies.

Advertisement