1/39
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the this pointer in C++?
A pointer that refers to the current/invoking object inside a member function.
Why is the this pointer useful in constructors like Rectangle(int width, int height)?
It distinguishes object data members from parameters with the same names.
What does this->width = width; mean?
Assign the parameter width to the current object's data member width.
Why is width = width; a problem in that constructor example?
It assigns the parameter to itself instead of updating the object's member.
What is a static member variable?
A class member that belongs to the class itself rather than to each individual object.
Are static member variables shared across objects of the class?
Yes.
Can a static member be accessed without creating an object first?
Yes.
Why must a static member variable be defined separately outside the class?
Because declaring it in the class only tells the class it exists; storage must be created separately.
What is the example definition of a static member variable?
int Person::counter = 0;
What does the Person counter example track?
How many Person objects have been created.
What is a static member function?
A class function that belongs to the class rather than any particular object.
Do static member functions have a this pointer?
No.
How do you call a static member function from outside the class?
Using the class name and scope operator, like Person::getPersonCount().
Why can static members be risky?
They behave a lot like shared global state and can cause thread-safety issues.
What are default parameters?
Parameters with default values that can be omitted in a function call.
Which parameters can be omitted when using default parameters?
Trailing parameters.
Where is the default value specified?
In the function declaration.
Can member functions use default parameters?
Yes.
What happens if you call printNumber() when the function is void printNumber(int i = 0)?
The argument 0 is used.
What rule applies after a parameter has a default value?
All following parameters must also have default values.
Why can default parameters cause overloading problems?
Because they can make calls ambiguous.
What is an exception in C++?
A standardized way to represent and handle exceptional situations.
What does a try block contain?
Risky code that may throw an exception.
What does throw do?
Generates an exception.
What does a catch block do?
Handles an exception.
How does C++ choose which catch block to use?
By matching the thrown type.
What does catch(…) do?
Catches any exception not caught by earlier handlers.
After an exception is handled, where does execution continue?
After the try-catch block.
What usually happens to uncaught exceptions?
The program terminates.
What is std::exception?
The standard base exception class in C++.
What header provides std::exception according to the slides?
Name some standard exception subclasses from the slides.
std::bad_alloc, std::runtime_error, std::invalid_argument
Why is catch(const exception& e) good practice?
It avoids modifying the exception and avoids unnecessary copying.
What does e.what() provide?
A message describing the exception.
What is a custom exception?
An exception class you define yourself, usually by inheriting from std::exception and overriding what().