The constructor from the inherited class, I require passing a non-trivial object. Similar to this:
MyFoo::MyFoo() : SomeBase( complexstuff )
{
return;
}
complexstuffhas little to do with MyFoo, so I did not want to miss it.
Instead of writing some kind of temporary 1-off function that returns complexstuff, I used lambda. It took me a few minutes to figure out that I should call a lambda. So now my code is as follows:
MyFoo::MyFoo() : SomeBase(
[]()
{
return complexstuff;
} () )
{
return;
}
If you have not noticed this, it is subtle. But after the lambda body I had to put ()in order to tell the compiler to immediately “start” the lambda. It made sense after I realized what I did wrong. Otherwise, without ()calling lambda, gcc says something similar to this:
error: no matching function for call to 'SomeBase(<lambda()>)'
, , ? ++ 11 ++ 14 , , lambda, ? (), ?