簡體   English   中英

std :: bind函數中沒有可行的重載'='

[英]No viable overloaded '=' in std::bind function

我試圖將引用變量i_RootPath的值設置為while循環內的其他值(如果您單擊相應的按鈕)。 編譯不喜歡我分配i_RootPath的方式。 它說:

沒有可行的重載'='

如何從生成的按鈕調用的不同方法中成功更改“ i_RootPath”的值?

void NodeViewApp::AddToolbar( boost::filesystem::path& i_RootPath ) {

    boost::filesystem::path currentPath = i_RootPath;

    while( currentPath.has_root_path() ){
        WPushButton* currentButton = new WPushButton( "myfile.txt" );

        currentButton->clicked().connect( std::bind([=] () {
            i_RootPath = currentPath;
        }) );
        currentPath = currentPath.parent_path();
    }
}

在Lambda函數中,使用[=]值捕獲的變量是const 您似乎正在按值捕獲i_RootPath (以及其他所有內容),因此它是const

從您的代碼來看,您可能應該使用捕獲規范[=,&i_RootPath]通過引用僅捕獲i_RootPath

您也可以使用[&]通過引用捕獲所有內容,但是看起來您需要保留currentPath的恆定副本。 在這種情況下, [&,currentPath]也將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM