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,182
  • 3
  • 26
  • 45

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
  • 223,800
  • 12
  • 181
  • 301