Lifetime of object is over before destructor is called?

前端 未结 4 756
广开言路
广开言路 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:07

    No, there's no problem:

    Member objects come alive before a constructor body runs, and they stay alive until after the destructor finishes. Therefore, you can refer to member objects in the constructor and the destructor.

    The object itself doesn't come alive until after its own constructor finishes, and it dies as soon as its destructor starts execution. But that's only as far as the outside world is concerned. Constructors and destructors may still refer to member objects.

提交回复
热议问题