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. The compiles does not like the way I assign 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?
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
[=]
areconst
. You seem to be capturingi_RootPath
(and everything else) by value, thus it isconst
.Judging by your code, you should probably use the capture specification
[=,&i_RootPath]
to capture onlyi_RootPath
by reference.You could also use
[&]
to capture everything by reference, but it looks like you need to keep a constant copy ofcurrentPath
. In that case,[&,currentPath]
would also work.