文章目录
Non-static Data Member Initializers
C++11 中如下两种写法均合法(C++98不支持):
struct A
{
int m;
A() : m(7) {
}
};
struct B
{
int m = 7; // non-static data member initializer
};
除此之外, 也可以在构造函数中覆写:
struct C
{
int m = 7;
C() : m(14) {