了解构造函数初始化列表
Understanding Constructor initializer list
我正在学习构造函数。我感到困惑的一部分是构造函数的初始化列表部分。例如看看下面的代码
class a{
Public:
typedef std::string::size_type pos;
s() = default;
s(pos ht, pos wt, char c) : height(ht), width(wt), contents(ht * wt, c);
private:
pos height, width;
std::string contents;
};
我没有 understand/cannot 阅读的部分是最后一个列表初始值设定项 contents(ht * wt, c)
我从未见过其中包含 2 个参数(?)的列表初始值设定项。我该如何阅读 contents(ht * wt, c)
?
初始化列表调用构造函数,因此调用constructor of contents
that accepts two arguments(在link中填充构造函数)。
我正在学习构造函数。我感到困惑的一部分是构造函数的初始化列表部分。例如看看下面的代码
class a{
Public:
typedef std::string::size_type pos;
s() = default;
s(pos ht, pos wt, char c) : height(ht), width(wt), contents(ht * wt, c);
private:
pos height, width;
std::string contents;
};
我没有 understand/cannot 阅读的部分是最后一个列表初始值设定项 contents(ht * wt, c)
我从未见过其中包含 2 个参数(?)的列表初始值设定项。我该如何阅读 contents(ht * wt, c)
?
初始化列表调用构造函数,因此调用constructor of contents
that accepts two arguments(在link中填充构造函数)。