0

我目前正在编写一个firebreath C++ NPAPI插件,并且试图从插件内部调用boost :: thread。我构建它的平台是Ubuntu Linux 13.04。下面是类的声明和相关的成员函数实现的骨架:在boost :: thread构造函数中调用boost :: bind()的编译器错误

class EmulatorLaunchPluginAPI : public FB::JSAPIAuto 
{ 
public: 
    EmulatorLaunchPluginAPI(const EmulatorLaunchPluginPtr& plugin, 
          const FB::BrowserHostPtr& host):m_plugin(plugin), m_host(host) 
    { 
     registerMethod("launch_emulator", 
        make_method(this, &EmulatorLaunchPluginAPI::launch_emulator)); 
     registerMethod("launch_emulator_thread", 
        make_method(this, &EmulatorLaunchPluginAPI::launch_emulator_thread)); 
    } 
    virtual ~EmulatorLaunchPluginAPI() {}; 
    EmulatorLaunchPluginPtr getPlugin() 
    { 
     EmulatorLaunchPluginPtr plugin(m_plugin.lock()); 
     if (!plugin) { 
      throw FB::script_error("The plugin is invalid"); 
     } 
     return plugin; 
    } 

    bool launch_emulator(const std::string& ,const FB::JSObjectPtr&) 
    { 
     emt(boost::bind(//boost::type<void>(), 
     &EmulatorLaunchPluginAPI::launch_emulator_thread, 
     this, 
     cmd, 
       callback)); 
     return true; 
    } 
    void launch_emulator_thread(const std::string& , const FB::JSObjectPtr&) 
    { 
     //thread body logic here 
     int result = 0; 
     result = invoke_command(cmd); 
     //callback to the browser 
     callback->InvokeAsync("", FB::variant_list_of(shared_from_this())(result)); 
    } 

private: 
    int invoke_command(const std::string&) 
    { 
     int res = system("/usr/bin/firefox"); 
     return res; 
    } 

    EmulatorLaunchPluginWeakPtr m_plugin; 
    FB::BrowserHostPtr m_host; 
    boost::thread emt; 
}; 

I am getting the following compile error for the code fragmented highlighted above: 

[54%]大厦CXX对象的项目/ EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir/EmulatorLaunchPluginAPI.cpp.o /家庭/阿贾伊/下载/firebreath-FireBreath-c335f5b/projects/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp:在成员函数 '布尔EmulatorLaunchPluginAPI :: launch_emulator(常量字符串&,常量JSObjectPtr &)': /家庭/阿贾伊/下载/ firebreath-fireBreath-c335f5b /项目/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp:94:30:error:不匹配调用'(boost :: thread)(boost :: _ bi :: bind_t &,co nst boost :: shared_ptr &>,boost :: _ bi :: list3,boost :: _ bi :: value>,boost :: _ bi :: value>>>)' make [2]:* [projects/EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir/EmulatorLaunchPluginAPI.cpp.o]错误1个 化妆[1]: [项目/ EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir /所有]错误2 化妆:* * [全部]错误2

我是Boost Libraries的新手,我也尝试了解boost :: bind是如何工作的,但是我无法解决这个错误。有人能帮我理解编译器的行为吗?

问候, 阿贾伊

+0

请,使用C++注释以表明错误的网站,cuz'*** emt(...'看起来像'emt'的三重引用。和下一个'; *** return'我的内部解析器得到ICE%) – zaufi

+0

也有错误的w/错误信息。它看起来像部分复制粘贴...调用'(boost :: thread)(boost :: _ bi :: bind_t&,const boost :: shared_ptr&>' - 我没有看到相应的开放角度支架 – zaufi

+0

@zaufi:感谢评论...我有将编译器输出封装在引起文本误报的块引用中......请在文章的修订版中找到原始错误...关注,Ajay – user2688183

回答

0

尝试改变行:

emt = boost::thread(&EmulatorLaunchPluginAPI::launch_emulator_thread, this, cmd, callback)); 
0

我还没有看到明确的错误信息(特别是我被弄得shared_ptr W/OA模板类型和后悬挂>),但我看到在你的代码的一些错误呢:

  1. launch_emulator使用本代码无法观察到的smth。例如命名为cmdcallback。用我的心灵感应,我想错过功能参数名称(我是正确的?)

  2. 类包含初始化boost::thread实例 - 你必须在构造函数初始化它,因为这个类没有副本构造函数或赋值运算符(针对C++ 11模式下,它有移动构造函数/分配

  3. launch_emulator你叫operator()boost::thread实例。这个类没有这样的成员,所以,我想你缩短了错误信息这个事实其实...

+0

感谢您对复制构造函数的评论......已经解决了我的问题!!我同意这是非常基本的: - )...我改变了从类字段的emt使其成为launch_emulator()的局部变量。代码已经编译完成! – user2688183

相关问题