473,573 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Boost::Bind strange compilation errors

P G
I hope this is on topic here. I have a problem compiling a simple
example of the use of boost::bind. Please take a look at the program
below.
/*************** *************** *************** *************** **************/

#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <memory>

using namespace boost;

struct X{

void f()
{
std::cout<<"Bin d Test\n";
}
};

int main()
{

X x;

shared_ptr<X> p(new X());

bind(&X::f, p)(); //fine

bind(&X::f, &x)(); //fine

bind(&X::f, ref(x))(); //fine

bind(&X::f, x)(); //will not compile

return 0;
}

/*************** *************** *************** *************** *********/

I can bind the member function ponter to a smart pointer, to an
ordinary pointer, or to a reference wrapper but I get compile errors
in the last case.
The documentation suggests that bind should make a copy of x. I have
used two compilers (MSVC 2003 and gcc 3.2) and both of them barf on
the last invocation of bind.

The GCC error message is:

c:/boost/boost/bind/mem_fn_template .hpp: In member function `R
boost::_mfi::mf 0<R, T>::call(U&, const T*) const [with U = const X,
R =
void, T = X]':
c:/boost/boost/bind/mem_fn_template .hpp:51: instantiated from `R
boost::_mfi::
mf0<R, T>::operator()( U&) const [with U = const X, R = void, T = X]'
c:/boost/boost/bind.hpp:186: instantiated from `R
boost::_bi::lis t1<A1>::opera
tor()(boost::_b i::type<R>, F, A&) const [with R = void, F =
boost::_mfi::mf 0<voi
d, X>, A = boost::_bi::lis t0, A1 = boost::_bi::val ue<X>]'
c:/boost/boost/bind/bind_template.h pp:21: instantiated from
`boost::_bi::re sul
t_traits<R, F>::type boost::_bi::bin d_t<R, F, L>::operator()( ) [with R
= void, F
= boost::_mfi::mf 0<void, X>, L =
boost::_bi::lis t1<boost::_bi:: value<X> >]'
b.cpp:36: instantiated from here
c:/boost/boost/bind/mem_fn_template .hpp:32: invalid conversion from
`const X*'
to `X*'

Has anybody encountered this?

Thanks.
Jul 22 '05 #1
2 2917
In article <62************ **************@ posting.google. com>,
qu*******@hotma il.com (P G) wrote:
/*************** *************** *************** *************** **************/

#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <memory>

using namespace boost;

struct X{

void f()
{
std::cout<<"Bin d Test\n";
}
};

int main()
{

X x;

shared_ptr<X> p(new X());

bind(&X::f, p)(); //fine

bind(&X::f, &x)(); //fine

bind(&X::f, ref(x))(); //fine

bind(&X::f, x)(); //will not compile

return 0;
}

/*************** *************** *************** *************** *********/

I can bind the member function ponter to a smart pointer, to an
ordinary pointer, or to a reference wrapper but I get compile errors
in the last case.
The documentation suggests that bind should make a copy of x. I have
used two compilers (MSVC 2003 and gcc 3.2) and both of them barf on
the last invocation of bind.


Your sample compiles for me using Metrowerks Pro 9 and boost 1.31.0.
I.e. the boost authors intend for your sample to compile.

-Howard
Jul 22 '05 #2
P G
Howard Hinnant <hi*****@metrow erks.com> wrote in message news:<hi******* *************** *****@syrcnyrdr s-03-ge0.nyroc.rr.co m>...
In article <62************ **************@ posting.google. com>,
qu*******@hotma il.com (P G) wrote:
/*************** *************** *************** *************** **************/

#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <memory>

using namespace boost;

struct X{

void f()
{
std::cout<<"Bin d Test\n";
}
};

int main()
{

X x;

shared_ptr<X> p(new X());

bind(&X::f, p)(); //fine

bind(&X::f, &x)(); //fine

bind(&X::f, ref(x))(); //fine

bind(&X::f, x)(); //will not compile

return 0;
}

/*************** *************** *************** *************** *********/

I can bind the member function ponter to a smart pointer, to an
ordinary pointer, or to a reference wrapper but I get compile errors
in the last case.
The documentation suggests that bind should make a copy of x. I have
used two compilers (MSVC 2003 and gcc 3.2) and both of them barf on
the last invocation of bind.


Your sample compiles for me using Metrowerks Pro 9 and boost 1.31.0.
I.e. the boost authors intend for your sample to compile.

-Howard


Thanks for verifying that I wasn't misusing the library.

I just downloaded version 1.31 (I had version 1.30 previously) and
both compilers now accept the same code.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2718
by: Arturo Cuebas | last post by:
The program below contains a compile error. Following the program you will find the typical fix then my idea for a library that facilitates a more elegant fix. #include <boost\bind.hpp> using namespace boost; struct C {
0
1021
by: Russell Hind | last post by:
Is it possible to create a boost::bind object for a managed class method? With non-managed classes, I can do boost::function<void ()> f = boost::bind(&Class_c::Function, this); Is there a way to do this for __gc classes? I do want to be able to assign the result to a boost::function, but can write my own wrapper if necessary. Thanks
2
2260
by: IndyStef | last post by:
I am trying to use boost's bind on a member function, on the VC8 compiler. After using several different attempts, I could not get it to work. Does anybody know what is wrong with the code below? The function that doesn't compile is foo::DoTheStuff. All three variations of the for-each loop won't build.
1
3836
by: Olaf Petzold | last post by:
Hi, at this time I try to combine Qt and boost. Unfortunately I've run into trouble: void QWidget::insertAction ( QAction * before, QAction * action ); class QAction : public QWidget { ... }; class ActionCategory { ...
1
2787
by: Tigera | last post by:
Greetings, I am trying to learn to use the Boost library, and I've run into a frustrating problem with the line marked here: #include <boost/function.hpp> #include <boost/functional.hpp> #include <boost/bind.hpp> #include <iostream>
0
1327
by: XHengDF | last post by:
I am a new gay to use the library boost, so i confused by some details! now, anybody could help me to explain the difference between boost::bind and boost::lambda::bind when i use the library. I mean when one will work but another don't. they all seem to be a functor,right? am i send to the rigjt group?
3
6800
by: =?iso-8859-1?B?Tm9yZGz2dw==?= | last post by:
Hey there, C++ Coders! I am learning multi-threading with boost and have come up with the following code example shown below. This example implements a test of the producer-consumer design pattern. gcc-4.1.2 however complains with errors about my use of boost::bind(). Doesn't bind support this way of specifying a function and its...
1
1583
by: kittymaguire | last post by:
I am using VC2005 and have refined new to be new (_NORMAL_BLOCK ,__FILE__, __LINE__) for the debug build so that the location of memory leaks are reported. The problem that I have is when, I try to bind a functor using boost::bind boost::bind(&BoostWorkerThread::Stop, this) I get an syntax error in function_template.hpp '('
3
3323
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using boost::bind), but the compiler complains, because of a type mismatch in an assignment which I think should be legal:
0
7684
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8006
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7768
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8058
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6400
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5288
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3729
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2191
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.