hashmap of pointers to functions
{ Note: multi-posted to [alt.comp.lang.learn.c-c++]. -mod }
I'm creating a hash_map with the values being pointers to functions,
and g++ is giving me a compiler error on my assignment. How I've
tried to implement this is to have a base class that defines a virtual
function and a typedef that corresponds to the template of that
function. Then when I assign values in the hash_map, I just point it
to the function in the extended class I want to add in. Here's what
I've got:
BaseSteamClass:
#include <iostream>
#include <ext/hash_map>
using __gnu_cxx::hash_map;
namespace streamclasses {
class BaseStreamClass {
public:
BaseStreamClass();
virtual ~BaseStreamClass() = 0;
virtual void toOStream(unsigned, std::ostream *ostream) = 0;
typedef void (*OStreamFunction)(unsigned, std::ostream*);
private:
__gnu_cxx::hash_map<int, OStreamFunction> StreamConversionMap;
};
}
Log Class:
namespace streamclasses {
class Log:public streamclasses::BaseStreamClass {
Log();
virtual ~Log();
void toOStream(unsigned, std::ostream *ostream);
};
}
And here's what I'm calling:
StreamConversionMap[0] = &streamclasses::Log::toOstream;
The compiler error is
cannot convert ?void (streamclasses::Log::*)(unsigned int,
std::ostream*)? to ?void (*)(unsigned int, std::ostream*)? in
initialization
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]