- Objects that are const, and references or pointers toconstobjects, maycall onlyconstmember functions.
-
The IO classes aretypes that cannot be copied, so we may only pass them by reference
-
A mutabledata memberis never const, even when it is a member of aconstobject. Accordingly, aconstmember function may change amutablemember.
-
in-class initializers must use either the=form of initialization (whichwe used when we initialized the the data members ofScreen) or the direct form ofinitialization using curly braces (as we do forscreens).
-
We can prevent the use of a constructor in a context that requires an implicitconversion by declaring the constructor asexplicit:
class Sales_data { public: Sales_data() = default; Sales_data(const std::string &s, unsigned n, double p): bookNo(s), units_sold(n), revenue(p*n) { } explicit Sales_data(const std::string &s): bookNo(s) { } explicit Sales_data(std::istream&); // remaining members as before
<span style="font-family: Arial, Helvetica, sans-serif;">};</span>
7.1Defining Abstract Data Ty &7.3Additional Class Features &7.5
最新推荐文章于 2023-03-14 14:14:19 发布