class CSub2
{
public:
    CSub2()
    {
        cout << "默认构造函数:" <<  this <<endl;
    }

    CSub2(int x) : m_x(x)
    {
        cout << "构造函数:" << m_x << ":" << this << endl;
    }

    CSub2& operator= (const CSub2& t)
    {
        cout << "赋值操作符:" << t.m_x << ":" << this << ":" << &t << endl;
        return *this;
    }

    virtual void test()
    {

    }
    int m_x;
};


class CSub
{
public:
    CSub() : a(10)
    {
        b = CSub2(18);
    }

    virtual void test()
    {

    }

    CSub2 a;
    CSub2 b;
};




int main()
{
    CSub tt;
    cout << &tt.a << endl;
    cout << &tt.b << endl;

    return 0;
}

 执行结果:

构造函数:10:0x0047FAA0

默认构造函数:0x0047FAA8

构造函数:18:0x0047f8ec

赋值操作符:18:0x0047FAA8:0x0x0047f8ec

0x0047FAA0

0x0047FAA8

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-06-02
  • 2021-11-11
猜你喜欢
  • 2021-09-09
  • 2022-12-23
  • 2021-12-14
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案