-
Classes: A Deeper Look, Part 2–STRUCTURED PROGRAMMING Course Notes
Classes: A Deeper Look, Part 2 ‘const’ (Constant) Objects and ‘const’ Member Functions The keyword ‘const‘ can be used to specify that an object is not modifiable and that any attempt to modify the object should result in a compilation error. C++ compilers disallow non-const member function calls on const objects. An attempt by a const member function to modify an object of its class is a compilation error. A member function (behavior) is specified as const both in its prototype and in its definition. A const object must be initialized. Constructors & destructors cannot be declared const. const data member & reference data members must be initialized using member…
-
Classes: A Deeper Look, Part 1–STRUCTURED PROGRAMMING Course Notes
Classes: A Deeper Look, Part 1 Time Class Case Study Preprocessor directives (a.k.a. “preprocessor wrappers”)–Use preprocessor directives to form preprocessor wrappers. Ex: //prevent multiple inclusions of header file #ifndef TIME_H #define TIME_H … #endif Preprocessor directives ‘#ifndef‘ (“if not defined”) and #endif are used to prevent multiple inclusions of a header file. (If the code between these directives has not previously been included in an application, #define defines a name that can be used to prevent future inclusions, and the code is included in the source code file. Tip: Use the name of the header file in upper case with the period replaced by an underscore in the #ifndef and…