explicit-destructor-call

Pseudo-destructor call does not destroy an object

南笙酒味 提交于 2019-11-27 01:59:56
Consider the following code: #include <iostream> typedef int t; t a=42; int main() { a.t::~t(); std::cout << a; //42 } I'm expected that a will be destroyed. But it is not true, why? How does do that pseudo-destructor call will be destroyed the object? Columbo But it is not true, why? §5.2.4/1: The only effect is the evaluation of the postfix-expression before the dot or arrow. Where the postfix-expression is the expression of the object for which the call takes place. Thus a pseudo destructor call, as a call to a trivial destructor, does not end the lifetime of the object it is applied to.

why is the destructor call after the std::move necessary?

微笑、不失礼 提交于 2019-11-27 01:32:23
问题 In The C++ programming language Edition 4 there is an example of a vector implementation, see relevant code at the end of the message. uninitialized_move() initializes new T objects into the new memory area by moving them from the old memory area. Then it calls the destructor on the original T object, the moved-from object. Why is the destructor call necessary in this case? Here is my incomplete understanding: moving an object means that the ownership of the resources owned by the moved-from

Pseudo-destructor call does not destroy an object

回眸只為那壹抹淺笑 提交于 2019-11-26 09:52:01
问题 Consider the following code: #include <iostream> typedef int t; t a=42; int main() { a.t::~t(); std::cout << a; //42 } I\'m expected that a will be destroyed. But it is not true, why? How does do that pseudo-destructor call will be destroyed the object? 回答1: But it is not true, why? §5.2.4/1: The only effect is the evaluation of the postfix-expression before the dot or arrow. Where the postfix-expression is the expression of the object for which the call takes place. Thus a pseudo destructor