Chapter 14

Instance and Static Members

  • Instance Variable: Unique copy for each object in a class.

  • Static Variable: Shared among all objects of a class.

  • Static Member Function: Can access static variables and be called without object instantiation.

Friends of Classes

  • Friend Function/Class: Accesses private members of another class. Declared via friend keyword.

  • Stand-alone or member functions can be friends.

Memberwise Assignment

  • Uses = to copy data between objects of the same class.

  • Example: instance2 = instance1; copies all member values.

Copy Constructors

  • A special constructor for initializing a new object from an existing one of the same class.

  • Default copy constructor does field-to-field copy, which may cause issues with pointers.

  • Programmer-defined copy constructor helps to manage dynamic memory properly.

Operator Overloading

  • Allows redefining operators (=, +, etc.) for class objects.

  • Requires function named operator followed by the operator symbol.

  • Overloaded operators can be defined as member functions or friend functions.

Object Conversion

  • Type of an object can be converted to another type using operator functions.

Aggregation

  • A class can be comprised of other classes, modeling a 'has-a' relationship.

Rvalue References and Move Semantics

  • Rvalue Reference: Refers to temporary objects, used for move semantics.

  • Improves performance for classes with dynamic memory.

  • Move and copy constructors/operators are necessary for efficient resource management.

Default Operations

  • Compiler generates default operations unless explicitly defined by the user.

  • Use default keyword to specify preferred default operations; delete keyword to prevent certain operations.