Jump to content
  • Advertisement
Sign in to follow this  

SDL Class (with surface) object assignment

This topic is 3473 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

I have a class which creates a surface from bitmap in the constructor (and frees that surface with the destructor). now of course since the surface is freed by the destructor i cannot assign an object of the class to another. how would i go about that? my best attempt is this: #include "SDL.h" #include "Maps.h" #include <iostream> TileSet::TileSet(int w, int h, int tcount, char * bmp) : width(w), height(h), tilecount(tcount), bitmap(SDL_LoadBMP(bmp)) { } TileSet::~TileSet() {SDL_FreeSurface(bitmap);} TileSet & TileSet::operator=(const TileSet & rs) { if (this == &rs) return *this; //std::strcpy(label, rs.label); //rating = rs.rating; //SDL_BlitSurface(rs.bitmap, NULL, bitmap, NULL); bitmap = SDL_ConvertSurface(rs.bitmap, rs.bitmap->format, rs.bitmap->flags); width = rs.width; height = rs.height; tilecount = rs.tilecount; return *this; }

Share this post

Link to post
Share on other sites
This is how I do it:

Surface &Surface::operator =(SDL_Surface *s)
// free the current surface

// if the source surface is not null, we need to free it first
surface = SDL_DisplayFormat(s);
surface = 0;

return *this;

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!