Here is what I'm trying to do:
//ImageCache.h:
#include <map>
#include <SDL.h>
typedef pair<const wchar_t*, SDL_Surface*> ImageNameAndSurface;
class ImageCache {
// Functions
public:
ImageCache();
~ImageCache();
SDL_Surface* getImage(const wchar_t* imageFilename);
// Variables
private:
map<const wchar_t*, SDL_Surface*> imageFileMap;
void freeImage(const pair<const wchar_t*, SDL_Surface*>& pr); //function for_each() is to operate on
};
//ImageCache.cpp:
#include "ImageCache.h"
#include <algorithm>
#include <SDL_image.h>
ImageCache::ImageCache() {}
void ImageCache::freeImage(const pair<const wchar_t*, SDL_Surface*>& pr)
{
wcout << "Freeing " << pr.first << endl;
SDL_FreeSurface(pr.second);
}
ImageCache::~ImageCache() {
for_each(imageFileMap.begin(), imageFileMap.end(), freeImage);
}
I'm using MSVC 2005 (compiling for Windows CE 5.0) and I get the following error:
error C3867: 'ImageCache::freeImage': function call missing argument list; use '&ImageCache::freeImage' to create a pointer to member
I understand that the function argument of for_each() expects a static function (and all of this works if I declare freeImage as static) but I'd like to know how to do this for non-static member functions. I don't understand how the implied "this" pointer is not getting passed to the call to freeImage(). Any help is greatly appreciated! I've Googled for an hour and haven't found quite this same situation for some reason.
I should add I'm trying to avoid overloading the () operator as this seems unnecessarily verbose and other similar, but obviously not compilable methods avoid this as well.