When are static objects destroyed in C ++
Can an object self-destruct?
when I call this-> ~ myclass () the object is not destroyed! I can still access it and get the correct values!
Yes, the object will be destroyed. And according to the C ++ standard it is "not ok" if it is destroyed again afterwards - if a new object has not been constructed in the same place in between (using "placement new"). And it doesn't matter what is in the destructor or whether it is "trivial" or not.
What you observe here is simply that not everything that is "not ok" according to the C ++ standard immediately leads to an error / crash / ....
The only question is whether you want to rely on your compiler "going anyway", or whether you want to write correct C ++ programs that work with any compiler (that implements the standard correctly).
The best thing is to forget very quickly that you can also write "this-> ~ classname ()".
On the other hand, "delete this" is IMO OK if it is ensured that the object was created with "new". And it is often used like this, e.g. when implementing "intrusive reference counting" (which can also be done without "delete this", but it is often the simplest solution).
- How can I not be racist
- Samsung is still paying Microsoft in 2016
- What emergency should you be prepared for?
- Can you decipher the word MAICLX?
- What do teachers want their students to know?
- How do heterosexual tomboy boys get friends?
- Narcissistic teenagers fail to understand the consequences and why
- Analytical chemistry is a tough class
- Is it worth it to be an academic professor
- How normal is it to masturbate
- India will be richer than America
- Established academic Western historians are biased
- Which is faster cheetah Ferrari or Lamborghini
- What is the MISA Act of India
- Which countries have banned the death penalty?
- Why is synchronization so important
- Save camels water
- Why is Sony locking the PS3
- Where is the best coffee in Vijayawada
- What is Elon Musk's dream
- What if Jon never gave Arya Needle
- How does a weightlessness chamber work
- What's the best movie in Telugu
- Makes ShopClues profit
- Will Russia participate in the 2020 Olympics
- We are at the peak of technology
- How hot Air Force children are
- Can stem cells revive the dead
- How do I create software in the editor
- Who is your favorite Kung Fu legend?
- Is it worth doing a prom
- What is Moz's Spam Score
- Do we need energy management solutions
- Has Lake Mead ever been full