Consider the following:
class DirectoryIterator;
namespace detail {
class FileDataProxy;
class DirectoryIteratorImpl
{
friend class Dir
You will indeed need to make some boost pieces friend for this. Basically make_shared
is calling the constructor and the fact that this is done from within a friend function does not matter for the compiler.
The good news though is that make_shared
is calling the constructor, not any other piece. So just making make_shared
friend would work... However it means that anyone could then create a shared_ptr<DirectoryIteratorImpl>
...
Is there a good reason not to use the good old shared_ptr
constructor? (If there is one, you might want to take a look at the make_shared
implementation and do it)
DirectoryIterator()
: impl( new detail::DirectoryIteratorImpl() )
{}
This way the call to the constructor is made from the DirectoryIterator
class that is already a friend of DirectoryIteratorImpl
without opening the door for all other code.
You can split your class into interface part and implementation part. The interface part is made public, and the implementation part can have public constructors. However, that means you have to use virtual inheritance.