在阅读TCPL第四版的时候看到,c++11支持类数据成员的初始化(In-Class Initializer),很有意思的功能。
测试代码如下:

class Date
{
  int year{2015};
  int month{10};
  int day{1};

public:
  Date(){}
};

int main(int argc, char ** argv)
{	
  Date d;
  return 0;
}

Date类的构造函数,通过初始化式,等价于

Data::Date(): year(2015), month(10), day(1){}

相关文章:

  • 2019-07-09
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
相关资源
相似解决方案