Boost logo

Boost Users :

From: Calderon Hector (hhcalderon_at_[hidden])
Date: 2006-03-24 06:54:58


I think boost::thread will beneficiate from a third constructor:

thread::thread( boost::shared_ptr< boost::function0<void>& > )

1. This constructor will allow to use functors that are heavy to copy or simply non - copiable.

2. This contructor will also allow polymorphic functors. For example, in the following code, the copying of the functor destroys its polymorphism (there is not any 2 printed in the output) :

#include <boost/thread/thread.hpp>
#include <iostream>

class A
{
public:
    unsigned int m_a;

    A( unsigned int a_a ) : m_a( a_a ) {}

    void Begin() {boost::thread ( * this );}

    void operator ()()
    {foo(); std::cout << m_a;}

    virtual void foo() {m_a = 3; std::cout << m_a;}
};

class B : public A
{
public:
    B( unsigned int a_a ) : A( a_a ) {}

    void foo() {m_a = 2; std::cout << m_a;}
};

int main()
{
    B b( 7 );
    b.Begin();

    std::cout << b.m_a;
    system("pause");
     return 0;
}

++Hector C.

----------------------------------
                
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.



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