मैं निर्माता में एक boost::shared_ptr<std::vector<std::string> > vec
प्रारंभ एक boost::shared_ptr<std::list<std::string> > list
के साथ इस सूची को प्रारंभ चाहते हैं?आरंभ किया जा रहा बढ़ावा :: shared_ptr <std :: वेक्टर <T>> बढ़ावा :: shared_ptr साथ <std::list<T>>
क्या यह संभव है?
Test.hpp
class Test
{
public:
Test(boost::shared_ptr<std::list<std::string> > list);
private:
boost::shared_ptr<std::vector<std::string> > vec;
};
Test.cpp
Test::Test(boost::shared_ptr<std::list<std::string> > list) : vec(list->begin(), list->end())
{
}
त्रुटि संदेश के भाग:
मैं इस कोशिश की
Test.cpp: In constructor ‘Test::Test(boost::shared_ptr<std::list<std::basic_string<char> > >)’:
Test.cpp:6:85: error: no matching function for call to ‘boost::shared_ptr<std::vector<std::basic_string<char> > >::shared_ptr(std::list<std::basic_string<char> >::iterator, std::list<std::basic_string<char> >::iterator)’
नहीं:
आदर्श रूप में, अपने कोड की तरह दिखना चाहिए। ये विभिन्न प्रकार हैं। आपको वेक्टर बनाना होगा और सूची सामग्री को कॉपी करना होगा। –
हालांकि साझा पॉइंटर्स के कंटेनरों के लिए वैध मामले हैं, क्या आप वाकई साझा जीवनकाल और गतिशील आवंटन ef कंटेनर की आवश्यकता है? – TartanLlama
बस एक टिप्पणी: 'boost :: shared_ptr' इतिहास है। इसके बजाए सी ++ 11 मानक सुविधाओं का उपयोग करें: 'std :: shared_ptr'। – rustyx