|
Boost Users : |
Subject: Re: [Boost-users] [function] How to use function with templated member functions
From: Igor R (boost.lists_at_[hidden])
Date: 2011-12-06 02:48:03
> struct my_reader
> {
> Â Â my_reader(bool full)
> Â Â {
> Â Â Â Â if( full )
> Â Â Â Â {
> Â Â Â Â Â Â _read_function = &my_reader::read_full<int>;
> Â Â Â Â }
> Â Â Â Â else
> Â Â Â Â {
> Â Â Â Â Â Â _read_function = &my_reader::read_partial<int>;
> Â Â Â Â }
> Â Â }
>
> Â Â void read()
> Â Â {
> Â Â Â Â _read_function(this);
> Â Â }
>
> private:
>
> Â Â template< typename T >
> Â Â void read_full()
> Â Â {
> Â Â Â Â std::cout << "reading full image" << std::endl;
> Â Â }
>
> Â Â template< typename T >
> Â Â void read_partial()
> Â Â {
> Â Â Â Â std::cout << "reading partial image" << std::endl;
> Â Â }
>
> Â Â boost::function<void (my_reader*)> _read_function;
> };
>
>
> int main(int argc, char* argv[])
> {
> Â Â my_reader r(false);
> Â Â r.read();
>
> Â Â Â Â return 0;
> }
>
> This doesn't compile with Visual Studio 2010 since the compiler cannot:
>
> "cannot convert from 'overloaded-function' to 'boost::function<Signature>'"
>
> Is there is way to make this happen?
http://www.boost.org/doc/libs/1_48_0/libs/bind/bind.html#with_member_pointers
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