using const
guarantee that a method doesn’t modify an argument:
1 | Star::Star(const char * s) {...} |
guarantee that a method won’t modify the object that invokes it:
1 | void Star::show() const {...} |
Here const means const Star * this
, where thispoints to the invoking object.
explicit smart pointer
Note that the auto-ptr constructor is explicit, meaning there is no implicit type cast from a pointer to an auto_ptrobject:1
2
3
4
5
6auto_ptr<double> pd;
double *p_reg = new double;
pd = p_reg; // not allowed (implicit conversion)
pd = auto_ptr<double>(p_reg); // allowed (explicit conversion
auto_ptr<double> pauto = p_reg; // not allowed (implicit conversion)
auto_ptr<double> pauto(p_reg); // allowed (explicit conversion
Note that the template allows you to initialize an auto_ptrobject to an ordinary pointer via a constructor.
STL library
container: a unit, like an array, that can hold several values.
iterator: pointer
? The type name for this iterator is a class scope typedef called iterator.
template
T is place holder
abc
having pure vitrual class
virual function
dynamic defining
preprocessing
use # to define // so that headfine won’t define twice
upcasting, downcasting
change pointer-to-derivedclass to pointer-to-baseclass is save