I am trying to make instance of singleton class using make_shared. Getting error while instantiating the singleton class.
Kindly note that if we change the instance pointer from shared_ptr to raw pointer, animalFactory = new AnimalFactory(), program works well.
I am trying using the below code, but getting the following error :
animal_factory.cpp:22:61: required from here
/usr/include/c++/6/ext/new_allocator.h:120:4: error: ‘AnimalFactory::AnimalFactory()’ is private within this context
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
animal_factory.cpp:3:1: note: declared private here
AnimalFactory::AnimalFactory()
Also, why so many layers of complexity? Singletons are the thing to avoid, not to make (and so are the recursive mutexes, by the way), but if you must make a singleton, the standard C++ solution is just a reference to a function-local static: