我有一个单例(来自boost :: serialization):
class LogManager : public boost::serialization::singleton<LogManager> { ... };以及获取实例的包装器:
inline LogManager &logManager() { return LogManager::get_mutable_instance(); }将此绑定到boost.python模块的正确方法是什么?
我试过了:
class_< LogManager, boost::serialization::singleton<LogManager> >("LogManager", no_init) ... ;结果 - 在控制台中出现了很多难看的错误文本。 怎么了?
I have a singleton (from boost::serialization):
class LogManager : public boost::serialization::singleton<LogManager> { ... };And wrapper for getting instance:
inline LogManager &logManager() { return LogManager::get_mutable_instance(); }What's the right way to bind this into boost.python module?
I tried:
class_< LogManager, boost::serialization::singleton<LogManager> >("LogManager", no_init) ... ;As a result - a lot of ugly error text in console. What's wrong?
最满意答案
除了在第二个参数中使用base bases<...>作为Autopulated指出,我想你也想要指定boost::noncopyable作为第三个模板参数,例如
bp::class_<LogManager, bp::bases<boost::serialization::singleton<LogManager> >, boost::noncopyable>("LogManager", bp::no_init)编辑 :此外,您需要为列出的任何基类提供类声明,例如
bp::class_<boost::serialization::singleton<LogManager>, boost::noncopyable>("Singleton", bp::no_init)或者,如果您不需要访问基类并且不会导出boost::serialization::singleton<LogManager>任何其他子项,那么您可以省略首先指定基类。 也就是说,如果你想要做的就是暴露LogManager类,那么下面的声明就可以了:
bp::class_<LogManager, boost::noncopyable>("LogManager", bp::no_init)In addition to using bases<...> in the second argument as Autopulated pointed out, I think you also want to specifiy boost::noncopyable as the third template argument, e.g.
bp::class_<LogManager, bp::bases<boost::serialization::singleton<LogManager> >, boost::noncopyable>("LogManager", bp::no_init)Edit: Also, you need have a class declaration for any base classes listed, e.g.
bp::class_<boost::serialization::singleton<LogManager>, boost::noncopyable>("Singleton", bp::no_init)Or, if you don't need access to the base class and won't be exporting any other children of boost::serialization::singleton<LogManager>, then you can omit specifying the base classes in the first place. That is, the following declaration is just fine if all you want to do is expose the LogManager class:
bp::class_<LogManager, boost::noncopyable>("LogManager", bp::no_init)更多推荐
发布评论