【发布时间】:2019-10-06 05:03:33
【问题描述】:
我正在尝试做类似以下的事情:
std::shared_ptr<asengine::PreCompileConfig> precompileconfigobj = std::make_shared<asengine::PreCompileConfig>();
std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, precompileconfigobj));
我收到以下错误:
/usr/include/c++/4.8/functional:1697:61: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.8/functional:1727:9: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
_M_invoke(_Index_tuple<_Indices...>)
经过简要研究,我发现线程函数需要参数对象的引用,而不是值。
std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, std::ref(precompileconfigobj));
但是,它仍然不能解决问题。任何解决问题的帮助将不胜感激。
【问题讨论】:
-
显示
RunRsyncDb方法的声明。我猜它是static那么你不需要将precompileconfigobj作为参数传递。 -
@rafix07 void RunRsyncDb(const std::shared_ptr
& shptrprecompileconfigobj, const std::shared_ptr & slog);
标签: c++11 shared-ptr ref