1/32
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 overloading in C++?
Having more than one definition for a function name or operator in the same scope.
How must overloaded functions differ?
By argument types and/or number of arguments.
Can functions be overloaded by return type only?
No.
Why does the compiler know which overloaded function to call?
Because it matches the call to the most appropriate argument list.
What is function overloading?
Using the same function name for multiple functions with different parameter lists.
Can member functions/methods also be overloaded?
Yes.
In the print example, what distinguishes the overloaded print functions?
They take different types: int, double, and string.
In the area example, what distinguishes the overloaded area functions?
They use a different number of arguments.
What is operator overloading?
Redefining an operator so it can work with user-defined types.
Why is operator overloading useful?
It lets objects be used with natural-looking operators like + or <<.
What is an example from the slides of operator overloading?
Overloading + for Complex objects.
What is another example from the slides?
Overloading << to print a Rectangle with cout.
Why is operator<< for Rectangle declared as a friend in the example?
So it can access private data members.
Why does the overloaded operator<< return ostream&?
So output operations can be chained together.
Can all operators be overloaded in C++?
No.
Which operators are shown in the slides as not overloadable?
::, *, ., and ?:
What does polymorphism mean?
Many forms.
What kind of polymorphism does the deck focus on?
Subtype polymorphism using base-class pointers and references.
Without virtual, what determines which method is called?
The type of the pointer/reference.
What is static dispatch?
Method selection determined by the compiler at compile time.
What does virtual do?
Enables dynamic dispatch.
With virtual, what determines which method is called?
The actual object type at run time.
Why use virtual?
When a method may be overridden in a derived class.
What is the tradeoff of virtual?
More flexibility, but some performance cost.
Where should virtual be specified?
In the header/declaration, not the implementation.
If a base-class method is virtual, does it stay virtual in descendant classes?
Yes.
What is a pure virtual method?
A virtual method with no implementation, declared like = 0.
Why are pure virtual methods used?
To force derived classes to implement specific methods.
What is an abstract class?
A class with one or more pure virtual methods.
Can an abstract class be instantiated?
No.
When is a derived class concrete?
When it implements all inherited pure virtual methods.
Why is Student instantiable in the last example?
Because it implements sayHello().
Why is Employee not instantiable in the last example?
Because it inherits a pure virtual method and does not implement it.