类成员原来也可以用已经初始化过的成员来初始化

来源:互联网 发布:学会计软件哪个好 编辑:程序博客网 时间:2024/05/01 11:33
class CBased
{
};

class CDerive : protected CBased
{
public:
    CDerive();
    virtual ~CDerive();

public:
    int m_size;
    int  m_len;

};

#include "Derive.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDerive::CDerive() //: m_size(2), m_len(m_size)
{
 m_size = 2;
  m_len = m_size;
}

void Main()
{
    CDerive d;
    cout << d.m_len;  //2

    try
    {
        throw CDerive();
    }
    catch (CBase &)
    {
        cout << "based" <<endl;
    }
    catch(...)
    {
        cout << "other" << endl;
    }
   //must other , not base
}
  
原创粉丝点击