[英]No viable overloaded '=' in std::bind function
I am trying to set the value of the referenced variable i_RootPath to different values inside of the while-loop, if you click on the corresponding button. 我试图将引用变量i_RootPath的值设置为while循环内的其他值(如果您单击相应的按钮)。 The compiles does not like the way I assign i_RootPath.
编译不喜欢我分配i_RootPath的方式。 It says:
它说:
No viable overloaded '='
没有可行的重载'='
How can I successfully change the value of "i_RootPath" from within the different methods called by the buttons generated? 如何从生成的按钮调用的不同方法中成功更改“ 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();
}
}
In a lambda function, variables that are captured by value with [=]
are const
. 在Lambda函数中,使用
[=]
值捕获的变量是const
。 You seem to be capturing i_RootPath
(and everything else) by value, thus it is const
. 您似乎正在按值捕获
i_RootPath
(以及其他所有内容),因此它是const
。
Judging by your code, you should probably use the capture specification [=,&i_RootPath]
to capture only i_RootPath
by reference. 从您的代码来看,您可能应该使用捕获规范
[=,&i_RootPath]
通过引用仅捕获i_RootPath
。
You could also use [&]
to capture everything by reference, but it looks like you need to keep a constant copy of currentPath
. 您也可以使用
[&]
通过引用捕获所有内容,但是看起来您需要保留currentPath
的恒定副本。 In that case, [&,currentPath]
would also work. 在这种情况下,
[&,currentPath]
也将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.