为什么对象生存期在非平凡的析构函数执行之前结束?

时间:2018-06-27 10:43:39

标签: c++ object destructor lifetime

我很困惑,因为我在C ++中找到了一些有关对象寿命的信息:

https://en.cppreference.com/w/cpp/language/lifetime

  

对于析构函数并非无关紧要的类类型的任何对象,   当析构函数开始执行时,生存期结束。

  1. 为什么,有什么根据吗?

  2. 如果这意味着我不应该这样做

    #include <iostream>
    
    class Foo {
    public:
     Foo() = default;
     Foo(const Foo&) = default;
     ~Foo() { std::cout << member; }
    
     int member = 666;
    };
    
    int main() {
      Foo a;
    }
    

0 个答案:

没有答案