1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

When is Destructor Called for temporary variables?

Discussion in 'C++' started by LarryChen, Jul 7, 2010.

  1. LarryChen

    LarryChen New Member

    Joined:
    Jun 23, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Here is the code,
    Code:
    class A
    {
    };
    
    A foo(A a)
    {
           return a;
    }
    
    int main()
    {
         A a;
         foo(a);
         
         return 1;
    }
    
    As we know, two temporary variables will be generated. One is when a is passed to foo and another one is when foo returns a A object. But when exactly is destructor invoked for these two temporary variables?[/QUOTE]
     

Share This Page