How do temporary objects get created during Reference initialization?

From your edit: 12.2 states that a temporary is created in the cases when you initialize a const reference where it refers to a prvalue. For example.

From your edit: 12.2 states that a temporary is created in the cases when you initialize a const reference where it refers to a prvalue. For example: double d = 3.14; const int &r = d; the compiler transforms this code into something like this: int temp = d; // creates a temporary int const int &r = temp; // reference is bound to that temporary The lifetime of temporary that is bound to a const reference is the lifetime of the reference. I.e.

The temporary is destroyed when the reference goes out of the scope.

Edited the question. :) – Anisha Kaul Dec 21 '11 at 7:22 and the scope of the reference is limited to these {} braces? – Anisha Kaul Dec 21 '11 at 7:44 2 Yes, the scope of const reference that is bound to a temporary is the scope in which a temporary is created, i.e.

When you exit the scope the named const reference that is bound to a temporary is destroyed and destructor for the temporary object is called. – cpx Dec 21 '11 at 7:59 Thanks. :) Can you look in here too.

:) stackoverflow.com/questions/8585924/what... – Anisha Kaul Dec 21 '11 at 8:03 1 No, because then it would depend on the lifetime an object. For example: A reference can be bound to an lvalue which may be a static object whose lifetime is the end of program. When a non-const reference goes out of the scope it doesn't mean that object bound to that reference would get destroyed.

On the other hand, you can only bind a const reference to an rvalue which refers to a temporary object. It gets destroyed as soon as the const reference goes out of the scope because it was supposed to extend the lifetime of a temporary object. I hope I understood your question.

– cpx Dec 21 '11 at 12:27.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions