Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: make_shared and friends. |
| Date | 2012-04-28 17:00 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <jnepts$i5s$1@dont-email.me> (permalink) |
| References | <5583145.28.1335476739188.JavaMail.geo-discussion-forums@ynnn35> |
On 27.04.2012 20:12, Jason McKesson wrote: > > Does the C++11 specification allow you to say that the `make_shared` > template is a friend, and thus guarantee that it can access the > appropriate private constructors of a class? Yes, there is syntax that > would make `make_shared` a friend. But does the spec *require* that > the constructors are called directly from `make_shared` itself, since > it cannot transfer friendship to any subsidiary object types? I don't think so. But as a practical matter make your destructor protected (or private), instead of the constructors. If the private constructors imply factory functions, then by switching to making the destructor non-public for the general case you reduce the number of construction/destruction support functions from M class specific factory functions, where M is the average number of constructors, to 1 common destroy function, which you can make a friend. And if you have make_shared as a single common factory function (note that this can be a bit unsafe since it or its wrapper will then have access to /all/ the constructors), then by doing the switch you introduce just 1 more function. No matter the number of such classes you create. Cheers & hth., - Alf -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Find similar
make_shared and friends. Jason McKesson <jmckesson@gmail.com> - 2012-04-27 11:12 -0700
Re: make_shared and friends. Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-04-27 11:47 -0700
Re: make_shared and friends. Jason McKesson <jmckesson@gmail.com> - 2012-04-28 17:02 -0700
Re: make_shared and friends. Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-04-29 23:59 -0700
Re: make_shared and friends. Jason McKesson <jmckesson@gmail.com> - 2012-05-01 11:29 -0700
Re: make_shared and friends. "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-05-02 11:11 -0700
Re: make_shared and friends. Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-05-02 11:12 -0700
Re: make_shared and friends. "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-28 17:00 -0700
csiph-web