
Hello,
I'm searching for a good solution for the following problem of making
a pair of a string and a pointer to a member function.
---
struct foo1 {
int bar1( int );
void bar2( );
};
int main() {
someobject.set_string( &foo1::bar1, "foobar1" );
someobject.set_string( &foo1::bar2, "foobar2" );
string = someobject.get_string( &foo1::bar1 );
pointer = someobject.get_pointer( "foobar2" );
}
---
The conversion of the string to the function pointer is possible, when
the function pointer is stored in some wrapper like mem_fn.
But the other way is more complicated. Since the member function
pointers are each types of their own, the pointers cannot be compared
and therefore cannot directly be stored in some list. Mem_fn also
doesn't seem to do this job. Using some compiler dependent extension
also isn't useful.
Using templated overloads does work for the conversion of member
function pointer to string - to some extent:
---
global template for setting the string:
template< typename foobar1_pointer_type, foobar1_pointer_type foobar1_pointer>
std::string overloaded_template() {
return "foobar1";
}
local call for getting the string:
string = overloaded_template