所以我尝试创建一些包装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