It's just an example of something that is hard(er) to do otherwise as it can require faffing about with
friend classes/functions. As you say, when there's no reason to return a
shared_ptr don't. A
unique_ptr or an
auto_ptr would be just as good in this example, or if you have an aversion to them a raw pointer would also work.
You could even expose a size variable and a placement new factory function for ultimate flexibility, allowing even stack allocation of these objects, but this would almost certainly be over the top.
Copyright © 2018, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds