lec 12: c++ programming - overloading and polymorphism

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:33 PM on 4/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

33 Terms

1
New cards

What is overloading in C++?

Having more than one definition for a function name or operator in the same scope.

2
New cards

How must overloaded functions differ?

By argument types and/or number of arguments.

3
New cards

Can functions be overloaded by return type only?

No.

4
New cards

Why does the compiler know which overloaded function to call?

Because it matches the call to the most appropriate argument list.

5
New cards

What is function overloading?

Using the same function name for multiple functions with different parameter lists.

6
New cards

Can member functions/methods also be overloaded?

Yes.

7
New cards

In the print example, what distinguishes the overloaded print functions?

They take different types: int, double, and string.

8
New cards

In the area example, what distinguishes the overloaded area functions?

They use a different number of arguments.

9
New cards

What is operator overloading?

Redefining an operator so it can work with user-defined types.

10
New cards

Why is operator overloading useful?

It lets objects be used with natural-looking operators like + or <<.

11
New cards

What is an example from the slides of operator overloading?

Overloading + for Complex objects.

12
New cards

What is another example from the slides?

Overloading << to print a Rectangle with cout.

13
New cards

Why is operator<< for Rectangle declared as a friend in the example?

So it can access private data members.

14
New cards

Why does the overloaded operator<< return ostream&?

So output operations can be chained together.

15
New cards

Can all operators be overloaded in C++?

No.

16
New cards

Which operators are shown in the slides as not overloadable?

::, *, ., and ?:

17
New cards

What does polymorphism mean?

Many forms.

18
New cards

What kind of polymorphism does the deck focus on?

Subtype polymorphism using base-class pointers and references.

19
New cards

Without virtual, what determines which method is called?

The type of the pointer/reference.

20
New cards

What is static dispatch?

Method selection determined by the compiler at compile time.

21
New cards

What does virtual do?

Enables dynamic dispatch.

22
New cards

With virtual, what determines which method is called?

The actual object type at run time.

23
New cards

Why use virtual?

When a method may be overridden in a derived class.

24
New cards

What is the tradeoff of virtual?

More flexibility, but some performance cost.

25
New cards

Where should virtual be specified?

In the header/declaration, not the implementation.

26
New cards

If a base-class method is virtual, does it stay virtual in descendant classes?

Yes.

27
New cards

What is a pure virtual method?

A virtual method with no implementation, declared like = 0.

28
New cards

Why are pure virtual methods used?

To force derived classes to implement specific methods.

29
New cards

What is an abstract class?

A class with one or more pure virtual methods.

30
New cards

Can an abstract class be instantiated?

No.

31
New cards

When is a derived class concrete?

When it implements all inherited pure virtual methods.

32
New cards

Why is Student instantiable in the last example?

Because it implements sayHello().

33
New cards

Why is Employee not instantiable in the last example?

Because it inherits a pure virtual method and does not implement it.