Well I've tried a few things:
class Tile{ typedef boost::shared_ptr<SDL_Surface> surface_ptr; public: Tile(int y_coord, int x_coord, int x_img_loc, int y_img_loc, int width = 32, int height = 32); Tile(){d_id = getNewID(); d_tile(0,&SDL_FreeSurface);} ~Tile(); ... private: ... surface_ptr d_tile;};
That gave me this error message
error C2064: term does not evaluate to a function taking 2 arguments
After reading some documentation that I only partially understood I found that the template had this format
template<class Y, class D> shared_ptr(Y * p, D d);
"Requirements: p must be convertible to T *. D must be CopyConstructible. The copy constructor and destructor of D must not throw. The expression d(p) must be well-formed, must not invoke undefined behavior, and must not throw exceptions.-from Boost's documentation on shared pointers"
From what I gathered 'd' is a functor. So I added this
typedef struct { void operator()(SDL_Surface* surface) const { cout << "deleting surface" << endl; if(surface) SDL_FreeSurface(surface); } } surface_destructor;
and changed the initializer to
Tile(){d_id = getNewID(); d_tile = surface_ptr(0,surface_destructor());}
I got the same error message so I googled some more and ran across this site http://learningcppisfun.blogspot.com/2007/05/custom-deleters-with-smart-pointers.html
So instead of trying to understand what was going on(brilliant of me I know...) I just tried to copy his pattern and ended up with this
typedef boost::shared_ptr<SDL_Surface,surface_destructor> surface_ptr(0,surface_destructor());...Tile(){d_id = getNewID(); d_tile.release();}
And got this error message(well, along with his 147 friends)
error C2977: 'boost::shared_ptr' : too many template arguments
You know I'm starting to think I don't have a clue as to what I'm doing :P