Skip to main content
gamedev.net
🔒 Locked

boost::function, boost::bind, method pointers

Started by thedustbustr 5 replies 3k views
Original Post
thedustbustr
thedustbustr
I need to assign a method to a boost::function object expecting a function with a similar signature. The docs show an example using bind. Why am I getting errors?

void CubeDemo::on_MoveForward(const Event* e) {/*...*/}
boost::function<void (const Event* e)>mf;
mf=boost::bind(on_MoveForward, this);

c:\dev\include\boost\bind\bind_template.hpp(18) : error C2091: function returns function
        c:\Documents and Settings\Dustin\Desktop\katana4\src\cubedemo.cpp(257) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled
        with
        [
            R=void (const Event *),
            F=boost::_mfi::dm<void (const Event *),CubeDemo>,
            L=boost::_bi::list1<boost::_bi::list_av_1<CubeDemo *>::B1>
        ]
c:\dev\include\boost\bind\bind_template.hpp(24) : error C2091: function returns function
c:\dev\include\boost\mem_fn.hpp(255) : warning C4180: qualifier applied to function type has no meaning; ignored
        c:\dev\include\boost\bind\bind_template.hpp(160) : see reference to class template instantiation 'boost::_mfi::dm<R,T>' being compiled
        with
        [
            R=void (const Event *),
            T=CubeDemo
        ]
Both C2901 and C4180 are repeated at least 10 times each at various lines in their respective files.
SiCrane
SiCrane
First, which version of MSVC are you using? Some versions of MSVC really don't like the boost::functionmf; syntax. You may have to use boost::function1 mf; instead. Also, it might help if you changed the third line to mf=boost::bind(&CubeDemo::on_MoveForward, this);
Fruny
Fruny
Quote:
Original post by SiCrane
First, which version of MSVC are you using?


From the error message's format, it's at least 7.0.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
SiCrane
SiCrane
Well yeah, but MSVC 7.0 is one of the ones that doesn't like the version of the syntax he used. :)
thedustbustr
thedustbustr
7.1. Preferred syntax is supported. The way I have it set up works perfectly fine for void(const Event*) functions. The errors are in bind, not functional.
thedustbustr
thedustbustr
Also, the errors did not change by saying boost::bind(&CubeDemo::on_MoveForward, this);
thedustbustr
thedustbustr
Found solution in docs. Don't know how I missed it the first million times. Thanks anyway.
mf=boost::bind(on_MoveForward, this, _1);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.