Sign in to follow this  
gapern

I want to put an SDL_Surface into a struct

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

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