|
Boost Users : |
From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-11-03 11:01:43
On Nov 3, 2004, at 10:28 AM, ~{5EH}BV5D~} wrote:
> Recently, I download boost 1.31.0 and compile it with Visual
> studio.net 2003.
> But the code below can't work properly:
>
> class A
> {
> public:
> A() { printf("constructor.\n"); }
>
> ~~A() { printf("destructor.\n"); }
>
> void operator () () { }
> };
>
> int main(int argc, char* argv[])
> {
> A a;
> boost::thread t(a);
> t.join();
> }
>
> In my system, it generate the message like this:
> D:\thread\Debug>thread.exe
> constructor.
> destructor.
> destructor.
> destructor.
> destructor.
> destructor.
> destructor.
>
> Who can tell me what's wrong with boost or something else?
The A object is being copied several times. Add in a constructor like
this to see what is going on:
A(const A&) { printf("copy constructor.\n"); }
If you really don't want copying to occur, use:
boost::thread t(boost::ref(a));
Doug
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net