所以我尝试围绕 boost.extension 函数创建一些包装器来创建类。所以我创建了一个函数:
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));
但是编译器告诉我C2248
它不能调用一些私有成员boost::scoped_ptr<T>
那么如何让我的退货......可退货//如何接收它?