Lifetime of object is over before destructor is called?

前端 未结 4 753
广开言路
广开言路 2020-12-03 11:38

I don\'t understand this:

3.8/1 \"The lifetime of an object of type T ends when: — if T is a class type with a non-trivial destructor (12.4), the

4条回答
  •  既然无缘
    2020-12-03 12:18

    "Lifetime" doesn't mean that. It is a precisely defined term in the standard that has a variety of implications, but it might not have all the implications that you would think. Members can still be used during construction and destruction, outside code can call member functions, etc, etc.

    Granted, it's a bit odd for client code to call member functions concurrently with the destructor, but not unheard of and certainly not disallowed by the language. In particular, std::condition_variable explicitly allows the destructor to be invoked while there are outstanding calls to condition_variable::wait(). It only prohibits new calls to wait() after the destructor starts.

提交回复
热议问题