|
Boost-Commit : |
From: pdimov_at_[hidden]
Date: 2008-02-19 10:40:58
Author: pdimov
Date: 2008-02-19 10:40:58 EST (Tue, 19 Feb 2008)
New Revision: 43323
URL: http://svn.boost.org/trac/boost/changeset/43323
Log:
Fix #1643.
Text files modified:
trunk/libs/bind/bind.html | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
Modified: trunk/libs/bind/bind.html
==============================================================================
--- trunk/libs/bind/bind.html (original)
+++ trunk/libs/bind/bind.html 2008-02-19 10:40:58 EST (Tue, 19 Feb 2008)
@@ -60,6 +60,7 @@
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_long_form">Inappropriate use of
bind<R>(f, ...)</A></h4>
<h4 style="MARGIN-LEFT: 40pt">Binding a nonstandard function</h4>
+ <h4 style="MARGIN-LEFT: 40pt">Binding an overloaded function</h4>
<h4 style="MARGIN-LEFT: 40pt">const in signatures</h4>
<h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_using">MSVC specific: using
boost::bind;</A></h4>
@@ -553,6 +554,37 @@
recognized by the short form of bind.
</p>
<P>See also "__stdcall" and "pascal" Support.</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>
<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:
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk