7.1Defining Abstract Data Ty &7.3Additional Class Features &7.5

来源:互联网 发布:java入门的好书 编辑:程序博客网 时间:2024/05/01 10:40

  • 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>
0 0