In C++, suppose I have a C++ class called A
, and inside it, I define a variable A* ptr;
. In the constructor, there is an instruction ptr = this
. Now, let's consider the following assignment initialization: A a = A()
. My main question is whether a.ptr == &a
is always true.
My primary concern is related to this assignment, which first creates a temporary object and then uses either the move constructor (possibly the copy constructor, I'm not entirely sure). I want to understand if the value of the ptr
member in the temporary object is always the same as the address of the object it will be assigned to (i.e., whether the address of the temporary object is always the same as the address of a
).
I have conducted experiments that seem to confirm this behavior, but I would like to know if this feature is guaranteed by the C++ standard.