C++ Demystified(c) A Self-Teaching Guide
-
OOP enables programmers to model programming objects after complex real-world objects, and to reuse existing, tested code.
-
An example in this chapter of information hiding or encapsulation is the use of public member functions to govern read and write access to private member variables .
-
Inheritance involves an is a relationship. An example is a student is a person.
-
Containership involves a has a relationship. Examples include that a car has an engine and a person has a birthday.
-
A structure is a programmer-defined data type that enables you to package related variables that may be of different data types.
-
When you declare a structure, you are declaring a data type. You need to declare a variable of that structure to create an instance of it.
-
You may initialize a structure using either an initialization list or a constructor.
-
You can nest one structure within another structure, such as a birthday member variable of a Person structure being a Date structure itself.
-
A structure may be passed by reference even if the function will not change the value of its member variables because less memory is required to pass the address of an object than the object itself, which may take up a lot of bytes. In this situation, you may precede the structure instance in the function argument list with the const keyword to prevent the function from inadvertently changing the values inside the structure instance.
-
Member variables are, by default, public in a structure but private in a class.
Категории