zoukankan      html  css  js  c++  java
  • 构造和析构 的顺序

    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    class B
    {
    public:
    B()
    {
    cout << "B()" << endl;
    }

    ~B()
    {
    cout << "~B()" << endl;
    }
    int m_b1;
    int m_b2;


    };

    class A
    {
    public:
    A()
    {
    m_pb1 = new B;
    m_pb2 = new B;
    cout << "A()" << endl;
    }

    ~A()
    {
    delete m_pb1;
    m_pb1 = nullptr;

    delete m_pb2;
    m_pb2 = nullptr;
    cout << "~A()" << endl;
    }
    B *m_pb1;
    B *m_pb2;


    };


    int main(){

    A *pa1 = new A;
    delete pa1;
    pa1 = nullptr;

    system("pause");
    return 0;
    }

  • 相关阅读:
    web--ajax--json
    4.26
    4.25
    4.23
    4.22
    4.20
    4.19
    4.18
    4月问题总结章
    4.17
  • 原文地址:https://www.cnblogs.com/Froger/p/7507382.html
Copyright © 2011-2022 走看看