Jump to content
  • Advertisement
Sign in to follow this  
gapern

I want to put an SDL_Surface into a struct

This topic is 3734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!