ostream << overloading

within a class you want to overload the << operator…

friend ostream& operator<<(ostream& o, const MyClass&  m) {
return o;


virtual destructors

if a base class ptr points to a derived class object, and we call delete on the base-class pointer…

if we don’t have a virtual destructor defined in the base class, we only call the destructor in the base class, the destructor of the derived class will not be called.

if we declare the destructor in the base class as virtual, then by default, the destructor in the derived class is also virtual. cpp will call the destructor of the derived class AND THEN the destructor of the base class

C++ pointer vs ref

manipulating underlying object requires de-referencing the ptr (e.g. to access method, use ->). reference is like an alias, you can just use the reference name as if it is the object variable name.

every overloaded operator function must only be a member of the class or a type T T& or T const&, where T is a class or enumeration type. can’t use pointers