How the member's initial value like 'contents(ht * wd, c)' works in constructor function in C++ Primer? -
i have read book c++ primer. in section 7.3.1: there 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 overloaded constructor function:
screen(pos ht, pos wd, char c): height(ht), width(wd), contents(ht * wd, c) { }
what initial value of contents(ht * wd, c)
, how works?
in section 7.1.4, there states:
the constructor initializer list of member names, each of followed member’s initial value in parentheses (or inside curly braces).
and have known string
has way string s(n, 'c')
initialize string such string s(10, 'c')
.
how works utilize string
constructor in constructor member initialization?
in advance.
Comments
Post a Comment