2
class A
{
public:
    A()
    {

    }
    A(A &copy)
    {

    }
};
void foo(A a)
{

}
int main()
{
    foo(A());
}

Will the temporary instance generated by calling A() be deleted after the copy constructor has ended or after the function foo has ended?

Tanmay Bhatnagar
  • 2,330
  • 4
  • 30
  • 50

1 Answers1

3

The temporary is destroyed at the end of the full-expression. That means after foo has returned.

A full-expression is an expression that is not a subexpression of another expression.

eerorika
  • 232,697
  • 12
  • 197
  • 326