forked from boostorg/bind
32
bind.html
32
bind.html
@@ -60,6 +60,7 @@
|
|||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_long_form">Inappropriate use of
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_long_form">Inappropriate use of
|
||||||
bind<R>(f, ...)</A></h4>
|
bind<R>(f, ...)</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_nonstd">Binding a nonstandard function</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_nonstd">Binding a nonstandard function</A></h4>
|
||||||
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_overloaded">Binding an overloaded function</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_const_arg"><b>const</b> in signatures</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_const_arg"><b>const</b> in signatures</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_using">MSVC specific: using
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_using">MSVC specific: using
|
||||||
boost::bind;</A></h4>
|
boost::bind;</A></h4>
|
||||||
@@ -553,6 +554,37 @@ int main()
|
|||||||
recognized by the short form of bind.
|
recognized by the short form of bind.
|
||||||
</p>
|
</p>
|
||||||
<P>See also <A href="#stdcall">"__stdcall" and "pascal" Support</A>.</P>
|
<P>See also <A href="#stdcall">"__stdcall" and "pascal" Support</A>.</P>
|
||||||
|
<h3><a name="err_overloaded">Binding an overloaded function</a></h3>
|
||||||
|
<p>An attempt to bind an overloaded function usually results in an error, as there
|
||||||
|
is no way to tell which overload was meant to be bound. This is a common
|
||||||
|
problem with member functions with two overloads, const and non-const, as in
|
||||||
|
this simplified example:</p>
|
||||||
|
<pre>struct X
|
||||||
|
{
|
||||||
|
int& get();
|
||||||
|
int const& get() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::bind( &X::get, _1 );
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<P>The ambiguity can be resolved manually by casting the (member) function pointer
|
||||||
|
to the desired type:</P>
|
||||||
|
<pre>int main()
|
||||||
|
{
|
||||||
|
boost::bind( static_cast< int const& (X::*) () const >( &X::get ), _1 );
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<P>Another, arguably more readable, alternative is to introduce a temporary
|
||||||
|
variable:</P>
|
||||||
|
<pre>int main()
|
||||||
|
{
|
||||||
|
int const& (X::*get) () const = &X::get;
|
||||||
|
boost::bind( get, _1 );
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
<h3><a name="err_const_arg"><b>const</b> in signatures</a></h3>
|
<h3><a name="err_const_arg"><b>const</b> in signatures</a></h3>
|
||||||
<p>Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with the
|
<p>Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with the
|
||||||
top-level <b>const</b> in function signatures:
|
top-level <b>const</b> in function signatures:
|
||||||
|
Reference in New Issue
Block a user