Boost logo

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