Re: boost:::bind problem syntax error with redefined new
* kittymaguire:
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.
Note that this precludes using any other placement new anywhere.
Also note that you need to define corresponding placement delete operators to
avoid memory leak when a constructor throws.
Formally you have UB if you're using any standard library header, but redefining
new is old (very bad, but old) technique so presumably practically safe.
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 '('
assign_functor(FunctionObj f, function_buffer& functor, mpl::true_)
{
new ((void*)&functor.data) FunctionObj(f);
}
This is very bad coding, the expression should be
::new (&functor.data) FunctionObj(f);
Whoever wrote that chose the wrong way to "qualify" the call.
But, anyway, this is a placement new, and you have precluded that by redefining new.
Instead define macros XNEW and XDELETE, and use them instead of 'new' and
'delete' directly.
Or, much better, use smart pointers and avoid the memory leaks... ;-)
if I do not refined new, then there is no compile error.
Question, how can I redefine new and still use boost.
See above.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?