Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-11-11 15:17:49


I have four easy questions regarding boost::shared_ptr:

1.) How do I pass a boost::shared_ptr to a function - via value or
reference?

void ByValue( boost::shared_ptr<Foo> pFoo );
void ByReference( boost::shared_ptr<Foo>& rFooPtr );

2.) When passing a raw pointee to a function you can declare the pointee
const. How do I pass a const boost::shared_ptr?

void ConstRaw( const Foo* pFoo );
void ConstSharedPtr( ??? );

3.) Does anything speak against passing a reference to a factory function
instead of returning the boost::shared_ptr?

boost::shared_ptr<Foo> Create( void )
{
    return boost::shared_ptr<Foo>( new Foo );
}

bool Create( boost::shared_ptr<Foo>& foo )
{
    // Make some validations and return false on error.
    // ...

    // Everyting is ok. Reset the pointee and return a success
    foo.reset( new Foo );

    return true;
}

4.) Can I test a boost::shared_ptr against NULL like a raw pointee?

Regards,

-Dirk


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk