From 3499038737740305135
X-Google-Thread: f78e5,6dda3f736a89f6d8
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news2.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Florian Goujeon <florian.goujeon@42ndart.org>
Newsgroups: comp.std.c++
Subject: Re: shared_from_this() from constructor
Date: Thu, 26 Aug 2010 15:45:39 CST
Organization: http://groups.google.com
Lines: 21
Sender: cppmods@cs.rpi.edu
Approved: austern@google.com
Message-ID: <d5302a72-2b38-41ba-a035-35fdbf616966@k10g2000yqa.googlegroups.com>
References: <
	de2bf2a0-c5b7-4ba2-a4e2-85842f0a0c4b@q22g2000yqm.googlegroups.com>
 <4bb0f4c3-5ef7-410f-be68-39cc0d61ca21@z28g2000yqh.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Thu, 26 Aug 2010 11:22:42 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
Xref: g2news1.google.com comp.std.c++:2912

Actually, the factory function is finally a pretty good solution
since - even without that default Item objects issue - if one tries to
add an Item object to a Container allocated on the stack (or on the
heap but without using a shared_ptr), an std::bad_weak_ptr will be
raised, as no shared_ptr instance will own that Container object.

Once the constructor of Container made private, a (friend) factory
function would force the user to allocate the Container objects on the
heap using a shared_ptr.

Sorry to the moderation for the double-post and thanks to you for your
help, Daniel.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



