Effective C++ 读后感笔记

1.赋值不一定是初始化。例如

AClassName::AClassName(const std::string &name, const std::string &address,
    const std::list<PhoneNumber> &phones)
{
     theName = name;          //这些都是赋值
      theAddress = address; //而非初始化
      thePhones = phones;
     numTimesConsulted = 0;
}

AClassName::AClassName(const std::string &name, const std::string &address,
    const std::list<PhoneNumber> &phones)
    :theName(name),                //这些都是初始化
      theAddress(address),
     thePhones(phones),
     numTimesConsulted(0)
{}        //构造函数本体不必做任何动作

2.类的默认继承级别为private,而struct默认为public。

  PS:①public继承,基类成员保有自己的访问级别:基类的public为派生类的public,基类的protected为派生类的protected;②protected继承,基类的public和protected在派生类中为protected;

      ③private继承,基类所有成员在派生类中为private。

原文地址:https://www.cnblogs.com/fengfengqingqingyangyang/p/3262526.html