How to receive map<string, factory<BaseClass, ConstructorType> >
from such function?
So I have
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;
}
map<string, factory<BaseClass, ConstructorType> >& lib_factories(lib_types.get());
if (lib_factories.empty()) {
cerr << "Producers not found!" << endl;
}
return lib_factories;
}
and I try to get its value with something like:
map<string, factory<PublicProducerPrototype, int> > producer_factories();
producer_factories = get_factories<PublicProducerPrototype, int>(simple_producer);
I try to generalize/simplify some of boost.extension methods for myself.
So how to receive map<A, B>&
correctly?
How to ini开发者_如何学Ctialize link correctly or how to return not link but real object? (sorry C++ nube)
If you need a reference to a map, you should declare the function as returning a reference, not a value:
template <class BaseClass, class ConstructorType>
map<string, factory<BaseClass, ConstructorType> >& get_factories (...
Of course, this assumes that the reference returned by lib_types.get()
is safe to pass out as a reference.
精彩评论