所以我嘗試創建一些包裝boost.extension功能的類創建。所以,我創建了一個功能:爲什麼我不能從函數返回Boost :: Scoped_ptr?
template <class BaseClass, class ConstructorType>
boost::scoped_ptr<BaseClass> get_class (shared_library & lib, std::string class_name, ConstructorType value) {
map<string, factory<BaseClass, ConstructorType> > lib_factories = get_factories<BaseClass, ConstructorType>(lib);
return boost::scoped_ptr<BaseClass> lib_class(lib_factories[class_name].create(value));
}
的呼叫:
template <class BaseClass, class ConstructorType>
map<string, factory<BaseClass, ConstructorType> > get_factories (shared_library & lib) {
type_map lib_types;
if (!lib.call(lib_types)) {
cerr << "Types map not found!" << endl;
cin.get();
}
map<string, factory<BaseClass, ConstructorType> > lib_factories(lib_types.get());
if (lib_factories.empty()) {
cerr << "Producers not found!" << endl;
cin.get();
}
return lib_factories;
}
,但最後還不是那麼重要。什麼是重要的 - 我不能讓我的函數返回=(
我嘗試這樣的方式:
boost::scoped_ptr<PublicProducerPrototype> producer = get_class<PublicProducerPrototype, int>(simple_producer, "simpleProducer", 1);
我也有嘗試:
boost::scoped_ptr<PublicProducerPrototype> producer (get_class<PublicProducerPrototype, int>(simple_producer, "simpleProducer", 1));
但是編譯器talls我C2248
它不能調用一些私人會員boost::scoped_ptr<T>
那麼如何讓我的退貨...可以退貨//如何收貨呢?
我的猜測,不知道更多關於錯誤,是複製構造函數是私有的(即該類打算是不可複製的),並且返回需要複製。你可能沒有在工作中使用正確的智能指針。 – 2011-04-20 00:00:53