|
Boost : |
From: Karl Mutch (karlmutc_at_[hidden])
Date: 2003-12-19 19:10:58
> seems to work, but why would you prefer this over ...
I had reduced this from a much larger example/context
sorry about the confusion.
Had my answer that indeed the VC7.1 is broken from Bronek
with grateful thanks to all that answered...
Karl
-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]On Behalf Of Peter Dimov
Sent: Friday, December 19, 2003 10:40 AM
To: Boost mailing list
Subject: Re: [boost] 1.30.2 - operator () with bind failing with
scoped_ptr
Karl Mutch wrote:
> Strangely something that used to work in 1.29 now does not in 1.30.2?
>
> Having switched to Microsoft Visual C++ 7.1 the following code that
> uses member functions fails which used to work on Visual C++ 6.0 SP4
> and 1.29. This is specific to operator () member functions. Named
> member functions
> and also operator methods such as "operator bool ()" or "operator ++
> ()" work. Could be a compiler issue?
>
> class X
> {
> public:
> void operator () () {}
> void operator ++ () {}
>
> void test ()
> {
> // Works
> boost::thread thread_works(boost::bind(&X::operator (), this));
> boost::scoped_ptr<boost::thread> thread_fails(new boost::thread(
> boost::bind(&X::operator ++, this)));
>
> // Fails with
> // error C2059: syntax error : ')'
> // error C2143: syntax error : missing ')' before ';'
> boost::scoped_ptr<boost::thread> thread_fails(new boost::thread(
> boost::bind(&X::operator (), this)));
>
> }
> };
Your code works with VC6 and others, it fails with VC 7.1. Looks like a
parser issue so you should report it to Microsoft.
boost::scoped_ptr<boost::thread> (thread_fails)(new boost::thread(
boost::bind(&X::operator (), this)));
seems to work, but why would you prefer this over
boost::thread thread_works(boost::bind(&X::operator (), this));
? And
boost::thread thread_works3( boost::ref(*this) );
is even simpler. As an aside, this is somehwat fragile, as it's possible for
the X object to be destroyed while the thread is still executing its
operator(); if you can switch to the preferred external thread model:
boost::thread t( X(...) ); // outside of X's member functions
where the thread itself keeps a copy of the X object you could avoid the
potential issues.
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk