I'd like to create a map of strings to member function pointers, so that I
can call a specific function based on a string. I'm compiling this using MS
Visual C++ 7.0 (VS.NET 2002)
class Foo;
/// Prototype for functions that extract a parameter from a module
typedef const void (Foo::*PARAM_GETTER)(std::string&);
/// A map of strings to parameter getters
typedef std::map<std::string, PARAM_GETTER> ParamGetterMap;
And then,
class Foo
{
protected:
ParamGetterMap m_getterMap;
};
class Bar : public AnotherBaseClass, public Foo
{
private:
// getter/setter helpers
void GetBar(std::string& strValue) { strValue = "something"; }
};
And finally,
Bar::Bar()
{
// Fill the parameter maps
m_getterMap.insert(make_pair("bar", GetBar)); // COMPLILE ERROR HERE
}
I get the following compile error:
C:\Microsoft Visual Studio .NET\Vc7\include\utility(41) : error C2440:
'initializing' : cannot
convert from 'void (__thiscall Bar::* const )(std::string &)' to
'PARAM_GETTER '
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or
function-style cast
Bar.cpp(41) : see
reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair
(const std::pair<char,void
(__thiscall Bar::* )(std::string &)> &)' being compiled
with
[
_Ty1=const std::string,
_Ty2=PARAM_GETTER
]
C:\Microsoft Visual Studio .NET\Vc7\include\utility(41) : error C2439:
'std::pair<_Ty1,_Ty2>::second' : member could not be initialized
with
[
_Ty1=const std::string,
_Ty2=PARAM_GETTER
]
C:\Microsoft Visual Studio .NET\Vc7\include\utility(56) : see
declaration of
'std::pair<_Ty1,_Ty2>::second'
with
[
_Ty1=const std::string,
_Ty2=PARAM_GETTER
]
Can anyone point out what I'm doing wrong here?
Thx x 10^6
--
Jim Johnson