|
Boost Users : |
Subject: [Boost-users] [Q] storing function pointers to member function
From: V S P (toreason_at_[hidden])
Date: 2009-02-20 03:40:25
I am trying to come up with a system that would let me
have a function (getter) for every member of the class
Using macros I can generate a 'get_<membername> function such that
struct my
{
float mem1;
}
would be
struct my
{
float mem1;
static const float& get_mem1( const my& )
{
return my.mem1;
}
};
Now, I would like to store pointer to the get_mem1 function in
a staticaly declared std::map
Using boost/function.hpp
I can declare a type for float
typedef boost::function<const float& (const my& ,const char* )>
tFget__float ;
and then
I can store it in, for example std::set<tFget__float>
The problem is that if I have another function that returns
a different data type (something other than float, for example
std::string)
I get a compilation error when trying to insert that function pointer
into
the set. There is a check implemented, I think, via the template system
that prevents compiler from making copies of one ponter type to another
-- even though they only differ by return type.
When I just do the assignment
tFget__float x= <function returning float>
or to function returning std::string -- I do not get the error.
So I would like to ask -- if there is a good way to store function
pointers
in a static array
(I later on plan to iterate ove the set of function pointers and get the
value of each data member into a stream )
thanks in advance,
Vlad
-- V S P toreason_at_[hidden] -- http://www.fastmail.fm - The professional email service
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net