12th Chapter Class
1 data abstraction is a programming (and design) technology that relies on interface and implementation separation. Encapsulation is a technique that combines low-level elements to form new, high-level entities.
2 the only chance to initialize a const or reference and a class-type data member without a default constructor is in the constructor initialization list.
3 Implicit type conversions: a constructor that can be invoked with a single argument defines an implicit conversion from the formal parameter type to the class type
Explicit only works on constructors to suppress implicit conversions.
4 There are three advantages to using a static member instead of a global object.
1 The name of the static member is in the scope of the class, so you can avoid conflicts with members of other classes or global object names.
2) can implement encapsulation. Static can be a private member and the global object may not.
3 It is easy to see through the reading program that the static member is associated with a particular class. This visibility can clearly show the programmer's intentions.
5 each static data member is an object associated with a class and is not associated with an object of that class.
6 static member functions do not have this pointer, cannot be declared as const (static data members can), cannot be declared as virtual functions, and cannot be used directly by non-static members.
7 The type of a static data member can be the class type to which the member belongs. A non-static member is qualified to be declared as a pointer or reference to its own class object:
Class Bar
{
Private
Static Bar mem1;
Bar *mem2;
Bar mem3;
}
8 Generally, static members of a class, like regular data members, cannot be initialized in the definition body of a class. is typically initialized at the time of definition.
Exception: As long as the initializer is a constant expression, an integer const static data member can be initialized in the class's definition body. However, you must still define outside the definition body of the class without specifying an initial value.