Imagine a scenario:
class B {
int f2() { return 5; }
}
class A {
B f1() { B b1(); return b1; }
}
A var;
int p = var.f1().f2();
When I call f1()
, an instance of class B
gets created. Then, on return, a temporary copy gets created and returned. Now my question is since I'm immediately calling f2()
on that returned object, will it immediately be deleted once f2
returns? Or will it live until the end of the scope? Is there any rule describing this scenario or is it compiler dependent?