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

相關問題