I have read the book C++ Primer. In section 7.3.1: there is a constructor of Screen
class:
class Screen {
public:
typedef std::string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd, char c): height(ht), width(wd),
contents(ht * wd, c) { }
char get() const { return contents[cursor]; }
inline char get(pos ht, pos wd) const;
Screen &move(pos r, pos c);
private:
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
};
And in the overloaded constructor function:
Screen(pos ht, pos wd, char c): height(ht), width(wd),
contents(ht * wd, c) { }
What is the initial value of contents(ht * wd, c)
and how it works?
In the section 7.1.4, there states:
The constructor initializer is a list of member names, each of which is followed by that member’s initial value in parentheses (or inside curly braces).
And I have known that string
has a way string s(n, 'c')
to initialize a string such as string s(10, 'c')
.
But how it works to utilize the string
constructor in the constructor member initialization?
Thanks in advance.