Boost logo

Boost :

From: Alp Mestan (alpmestan_at_[hidden])
Date: 2008-07-27 10:28:21


I think the safety goes first. So build you share_ptr<X> the way you do,
IMO.

On Sun, Jul 27, 2008 at 4:15 PM, Daniel Frey <d.frey_at_[hidden]> wrote:

> Hi,
>
> I have a question on make_shared. Consider a class which intends to
> force all instances to be handled via a shared_ptr. I used to do this by
> putting the ctors into the private section and adding static
> create()-methods in the public section. Example:
>
> class X
> {
> private:
> X( int, double );
>
> public:
> static shared_ptr<X> create( int i, double d )
> {
> return shared_ptr<X>( new X( i, d ) );
> }
> };
>
> Replacing the returned expression with make_shared<X>( i, d ) wouldn't
> work, since it requires a public ctor.
>
> Is there any solution to this or do I have to make a decision between
> efficiency and a safe interface for X?
>
> Regards, Daniel
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

-- 
Alp Mestan
--- http://blog.mestan.fr/
--- http://alp.developpez.com/
--- In charge of the Qt, Algorithms and Artificial Intelligence sections on
Developpez

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