I have C++14 code similar to this:
void C::f() {
int& ref = this->x;
auto lb = [&ref]() {
/* do stuff with "ref" */
};
if (foobar) {
// call lb when signal fires.
connect(object, &D::signal, [&lb]() {
lb();
});
} else {
lb();
}
}
I know that by the time I use lb
, this
will still be valid. But what about ref
and lb
. Is there any dangling reference with the code above ?
I found similar questions (here, there,...) but I couldn't draw a conclusion.