我遇到了一个名为“成员初始化器”的奇怪概念。
Here说:
C++11 added member initializers, expressions to be applied to members at class scope if a constructor did not initialize the member itself.
它的定义是什么?
有没有一些例子来说明它的用法?
最佳答案
它可能是指类内成员初始化器。这允许您在声明点初始化非静态数据成员:
struct Foo
{
explicit Foo(int i) : i(i) {} // x is initialized to 3.1416
int i = 42;
double x = 3.1416;
};
更多详情请见 Bjarne Stroustrup's C++11 FAQ .
关于c++ - C++11 中的 "member initializer"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18811742/