Term
16.2.0.1: A class is what kind of type? |
|
Definition
|
|
Term
16.2.0.2: Member functions can define the meaning of what in a class? |
|
Definition
initialization (creation), copy, move, and cleanup (destruction). |
|
|
Term
16.2.0.3: Members are accessed by what for objects and what for pointers? |
|
Definition
. (dot) for objects and -> (arrow) for pointers. |
|
|
Term
16.2.0.4: Can operators be defined for a class? |
|
Definition
Yes. For example, +, !, and [] can be defined for a class. |
|
|
Term
16.2.0.5: Is a class a namespace? |
|
Definition
Yes. A class is a namespace which contains its members. |
|
|
Term
16.2.0.6: What members provide the class's interface and what members provide implementation details? |
|
Definition
The public members provide the interface and the private members provide the implementation details |
|
|
Term
16.2.0.7: A struct is what kind of class? |
|
Definition
A struct is a class where the default members are public. |
|
|
Term
16.2.1.1: Functions declared within a class definition are called what. A struct is also a class.
struct Data {
int d, m, y;
void init( int dd, int mm, int yy ); void add_year( int n ); void add_month( int n ); void add_day( int n ); } |
|
Definition
This functions are called member functions. |
|
|
Term
16.2.1.2: Why do we need to specify the struct's name when defining it's member function?
void Date::init ( int dd, int mm, int yy) {} |
|
Definition
We need to specify the struct's name when we define it's member function because another struct might have a member function with the same name. |
|
|
Term
16.2.1.3: Does a class's member function "know" for which object it was invoked from. |
|
Definition
Yes. a member function knows what object it is invoked from. |
|
|
Term
16.2.2.1: By default can objects be copied. |
|
Definition
Yes. By default objects can be copied.
Date d1 = my_birthday // initialization by copy
Date d2 { my_birthday }; //initialization by copy |
|
|
Term
16.2.2.2: By default, when an object is copied where does the copied object get its data members? |
|
Definition
The copied object gets its data members by copying the original object's data member. This is has consequences that affect both the original an copied object! |
|
|
Term
16.2.2.3: What is a way for a Class to determine how it will be copied. |
|
Definition
The class can define it's own copy constructor. |
|
|
Term
16.2.2.4: An object will be copied when? |
|
Definition
When you pass by value, assignment, or return by value. |
|
|
Term
16.2.3.1: Can a nonmember function use a private member variable of a class? |
|
Definition
No, a non-member function can not use a private member variable of a class. |
|
|
Term
16.2.3.2: What are some advantages to restricting access to the data structure of a class? |
|
Definition
If an error occurs by taking an illegal value for a private member variable, then we know it was caused by code in a member function. This implies the first stage of debugging - localization - is completed before the program is even run.
A potential user need examine only the definitions of the member functions in order to learn to use the class.
Focusing on the design of a good interface simply leads to better code.
The protection of private data relies on restriction of the use of the class member names. It can therefore be circumvented by address manipulation and explicit type conversion |
|
|
Term
16.2.3.4: What does C++ protect against accidents or cheating? |
|
Definition
C++ only protects against accidents. It does not prevent against circumvention of the rules |
|
|