Operator Overloading, Function Overloading, Friendship, Modular Programming, and String Class

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

1/25

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:14 AM on 6/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

26 Terms

1
New cards

What is function overloading?

Multiple functions with the same name but different parameter lists

2
New cards

How can overloaded functions differ?

Different number of parameters and/or different parameter types

3
New cards

What type of polymorphism is function overloading?

Compile-time (static) polymorphism

4
New cards

Is the return type part of a function signature?

No

5
New cards

What does the compiler use to distinguish overloaded functions?

Their function signatures (name + parameter types)

6
New cards

What is operator overloading?

Redefining operators so they work with user-defined types

7
New cards

Why is operator overloading used?

To make objects behave more like built-in types and improve readability

8
New cards

What keyword is used to overload an operator?

operator

9
New cards

Which object calls an overloaded operator member function?

The object on the left side of the operator

10
New cards

What expression is equivalent to a + b?

a.operator+(b)

11
New cards

What is the general syntax for an overloaded operator member function?

ReturnType operatorOP(const ClassName& other) const
{
    // OP = operator(+, -, *)
}

12
New cards

What is the syntax for overloading +?

ClassName operator+(const ClassName& other) const
{
    return ClassName(member + other.member, member2 + other.member);
}

13
New cards

What is the syntax for overloading -?

ClassName operator-(const ClassName& other) const
{
    return ClassName(member - other.member, member2 - other.member2);
}

14
New cards

What is the syntax for overloading * (object × scalar)?

ClassName operator*(double scalar) const
{
    return ClassName(member * scalar, member2 * scalar);
}

15
New cards

What is usually returned by overloaded arithmetic operators (+, -, *,)?

A new object containing the result

16
New cards

What is a friend function?

A non-member function that can access private and protected members of a class

17
New cards

How is a friend function declared?

friend ReturnType functionName(...);

18
New cards

Where is a friend function declared?

Inside the class declaration

19
New cards

Is friendship reciprocal?

no

20
New cards

Why are friend functions commonly used with operator overloading?

To allow non-member operators to access private data

21
New cards

Why is operator<< usually implemented as a friend function?

Because the left operand is std::ostream, not the class object

22
New cards

What is the syntax for overloading <<?

friend std::ostream& operator<<(
    std::ostream& os,
    const ClassName& obj)
{
    // output members
    return os;
}

23
New cards

Why must operator<< return std::ostream&?

To allow chained output operations

std::cout << a << b;

24
New cards

Why might multiplication be overloaded as a friend function?

To allow a scalar on the left side

2.0 * v

25
New cards

What is the syntax for scalar × object multiplication?

friend ClassName operator*(
    float scalar,
    const ClassName& obj)
{
    return ClassName(...);
}

26
New cards

What are the rules of function overloading?

  • must share the exact same name

  • must have different parameter lists

  • cannot differ only by return type