संभव डुप्लिकेट:
How do I call ::std::make_shared on a class with only protected or private constructors?एक संरक्षित निर्माता नाशक साथ std :: shared_ptr का उपयोग कर
मैं एक वर्ग के लिए एक साझा सूचक बनाते हैं, और एक कारखाने विधि है कि रिटर्न करना चाहते हैं यह कन्स्ट्रक्टर \ विनाशक संरक्षित रखने के दौरान। चूंकि साझा पॉइंटर कन्स्ट्रक्टर या विनाशक तक नहीं पहुंच सकता है, इसलिए मुझे कंपाइलर त्रुटियां मिलती हैं।
मैं LLVM 4.1 उपयोग कर रहा हूँ, लेकिन मैं एक समाधान है कि संकलक स्वतंत्र हो सकता है के लिए देख रहा हूँ (निर्माता \ नाशक को सार्वजनिक करने के अलावा)।
class Foo
{
public:
static std::shared_ptr<Foo> getSharedPointer()
{
return std::make_shared<Foo>();
}
protected:
Foo(int x){}
~Foo(){}
};
किसी भी विचार:
यह एक कोड नमूना है?
और http://stackoverflow.com/questions/3541632/using-make-shared-with-a- संरक्षित-constructor-abstract-interface http://stackoverflow.com/questions/7521660/friend-function-of -stdmake से साझा की गई http://stackoverflow.com/questions/2590310/can-i-use-boostmake-shared-with-a-private-constructor आदि – interjay
और http://stackoverflow.com/questions/8202530/how विनाशक मुद्दे – interjay