What is a C++ class?
A class is a user-defined type that combines data with the functions operating on that data; its definition describes objects but usually creates none.
Study 8 Classes and Introductory Object-Oriented Programming with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a C++ class?
A class is a user-defined type that combines data with the functions operating on that data; its definition describes objects but usually creates none.
How do default access rules differ for struct and class?
Struct members are public by default, whereas class members are private by default. Both can contain the same kinds of members.
What are data members and member functions?
A data member stores an object’s state; a member function defines an operation associated with that object.
What does `const` after a member function mean?
The trailing `const` promises not to modify the object’s observable state, so the function can be called on a `const` object.
What does `ClassName::memberName` identify?
The scope resolution operator `::` identifies a class member when that member function is defined outside the class body.
What is encapsulation?
Encapsulation combines data and operations while controlling access, allowing a class to enforce rules instead of permitting arbitrary state changes.
What do public, private, and protected control?
`public` permits general access, `private` limits access to the class and its friends, and `protected` also permits access from derived classes.
What is a constructor?
A constructor initializes an object automatically; it has the class’s name and no return type, not even `void`.
Why use a member initializer list?
A member initializer list initializes data members before the constructor body executes and is the preferred initialization method.
What does `explicit` prevent on a single-argument constructor?
`explicit` prevents an undesirable implicit conversion by requiring construction to be written explicitly in relevant contexts.
When do you use `.` versus `->`?
Use `.` with an object and `->` with a pointer to an object. `pointer->member` is equivalent to `(*pointer).member`.
What relationship does public inheritance express?
Public inheritance expresses an “is-a” relationship: a derived object can be treated as an object of its public base type.