Dan*_*son 2 c++ boost wt boost-filesystem
我试图将引用变量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();
}
}
Run Code Online (Sandbox Code Playgroud)
在lambda函数中,由value捕获的变量[=]是const.你似乎是i_RootPath按价值捕捉(和其他一切),因此它是const.
根据您的代码判断,您应该使用捕获规范[=,&i_RootPath]来仅i_RootPath通过引用捕获.
您还可以使用[&]通过引用捕获所有内容,但看起来您需要保留一个常量副本currentPath.在那种情况下,[&,currentPath]也会有效.
| 归档时间: |
|
| 查看次数: |
350 次 |
| 最近记录: |