A step-by-step guide where we don't just learn what the code does โ we understand why every word, symbol, parameter, and line of code is used.
๐ Why I Created This Guide
Recently, a friend asked me to help her understand Operator Overloading in C++ because she was having difficulty understanding it from her training.
When I looked at the code, I realized something important.
The problem wasn't necessarily the Operator Overloading itself.
The problem was that many small C++ concepts were being used together .
For example, a beginner may see:
Time Time :: operator + ( const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and immediately have questions:
โ Why are there two Times ?
โ What does Time:: mean?
โ Why is the function called operator+?
โ What does const mean?
โ What does & mean?
โ What is t?
โ Where did the first object go?
โ Why do we need temp?
โ Why are we returning Time?
โ What is this?
โ Why does postfix ++ have int?
โ Why are ostream and istream used?
โ Why are << and >> used?
If these small questions aren't answered, it becomes very easy to memorize the syntax without understanding the concept .
So in this article, I want to explain Operator Overloading the way I would explain it to a friend sitting beside me .
The goal is not:
โ "Memorize this code."
The goal is:
โ
"Look at the code and understand why every part is there."
๐ What We Will Learn
By the end of this article, you should understand:
Classes and objects
Operators and operands
Unary vs Binary operators
Operator Overloading
Member operator functions
operator+()
operator-()
operator=()
Prefix ++
Postfix ++
Prefix --
Postfix --
Why postfix operators use a dummy int
this
*this
const
References using &
Return types such as Time and Time&
ostream
istream
operator<<
operator>>
Time addition
Time subtraction
Borrowing
Time normalization
How C++ can be thought of as translating operator expressions into function calls
๐งฑ Part 1 โ Before Operator Overloading
Before learning Operator Overloading, let's understand the object we are going to use.
We will create a class called Time.
1. What Is a Class?
Consider this:
class Time
{
int hours ;
int minutes ;
};
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
If you've already studied classes, this may look simple.
But let's slow down.
What does class mean?
class is a C++ keyword used to create a class.
A simple way to understand a class is to think of it as a blueprint .
Imagine an architect creates a blueprint for a house.
The blueprint describes:
rooms
doors
windows
structure
But the blueprint itself is not the actual house .
Similarly, our Time class is a blueprint.
It tells us:
"A Time object will contain information related to hours and minutes."
Visualize it like this:
Time
โโโโโโโโโโโโโโโโโ
โ BLUEPRINT โ
โ โ
โ hours โ
โ minutes โ
โโโโโโโโโโโโโโโโโ
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
2. What Are hours and minutes?
Inside the class we have:
int hours ;
int minutes ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
What is int?
int is a C++ data type used for storing whole numbers .
For example:
int age = 21 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Here:
int โ data type
age โ variable name
21 โ value
Similarly:
int hours ;
int minutes ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means our Time object will contain two integer variables:
hours
minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For example:
hours = 2
minutes = 40
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
represents:
2 hours 40 minutes
3. What Is an Object?
We have created our blueprint:
class Time
{
int hours ;
int minutes ;
};
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But we still haven't created an actual Time object.
To create one:
Time t ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Let's read this from left to right :
Time t
โ โ
type name
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Time is the class type we created.
t is the name of the object .
So:
Time t ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
simply means:
Create an object named t whose type is Time.
You can visualize it like this:
Time class
โโโโโโโโโโโโโโโโ
โ blueprint โ
โ โ
โ hours โ
โ minutes โ
โโโโโโโโฌโโโโโโโโ
โ
create object
โ
โโโโโโโโโโโโโโโโ
โ t โ
โโโโโโโโโโโโโโโโค
โ hours โ
โ minutes โ
โโโโโโโโโโโโโโโโ
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
4. Class vs Object
This distinction is extremely important.
๐ฆ Class
A class is the blueprint or definition .
class Time
{
int hours ;
int minutes ;
};
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฉ Object
An object is an actual object created from that class .
Time t ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We can create many objects from the same class:
Time t1 ;
Time t2 ;
Time t3 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Visual:
Time class
/ | \
โ โ โ
โโโโโโโ โโโโโโโ โโโโโโโ
โ t1 โ โ t2 โ โ t3 โ
โโโโโโโ โโโโโโโ โโโโโโโ
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
All three objects are created from the same class.
They have the same structure , but their values can be different.
For example:
t1 โ 2 hours 40 minutes
t2 โ 1 hour 30 minutes
t3 โ 5 hours 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
5. Objects Can Also Use Functions
A class can contain variables as well as functions .
For example:
class Time
{
public:
int hours ;
int minutes ;
void display ()
{
cout << hours << " hours "
<< minutes << " minutes" ;
}
};
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now:
Time t ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
creates an object called t.
That object can call the function:
t . display ();
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This means:
Call the display() function for object t.
Keep this idea in mind.
Later we will see:
t1 . operator + ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The same basic idea is involved:
An object can call a member function that belongs to its class.
โ๏ธ Part 2 โ Understanding Operators
Now let's move to operators.
You have already used operators many times.
For example:
int a = 10 ;
int b = 20 ;
int c = a + b ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Look at:
a + b
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There are three things:
a + b
โ โ โ
operand operator operand
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The + is the operator .
a and b are the operands .
6. What Is an Operand?
An operand is the value or object on which an operator works.
For:
10 + 20
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
the operator is:
+
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and the operands are:
10
20
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Visual:
+
/ \
/ \
10 20
โ โ
operand operand
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
7. What Does the + Operator Already Know?
C++ already knows how to use + with built-in data types.
For example:
10 + 20
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
produces:
30
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
C++ already knows rules for operations such as:
int + int
float + float
double + double
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But now we have created our own type:
Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And this creates a problem.
โ Part 3 โ The Problem We Need to Solve
Suppose we have:
Time t1 ;
Time t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and:
t1 = 2 hours 40 minutes
t2 = 1 hour 30 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now suppose we want to write:
Time t3 = t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
What should + do?
C++ knows:
10 + 20
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But C++ does not automatically know what this means :
t1 + t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
when t1 and t2 are Time objects.
We need to tell C++ what + should mean for our Time class.
And that is where:
โญ Operator Overloading
comes in.
8. What Is Operator Overloading?
A simple definition is:
Operator Overloading means giving an existing C++ operator a special meaning when it is used with objects of our own class.
Notice an important point:
We are not creating a new operator .
The operator already exists.
For example:
+
-
=
++
--
<<
>>
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We are simply teaching C++:
"When this operator is used with my Time objects, perform this operation."
For example:
t1 + t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
can be made to mean:
Add hours
+
Add minutes
+
Convert extra minutes into hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
9. Why Is Operator Overloading Useful?
Without Operator Overloading, we could create a normal function:
Time addTime ( Time t1 , Time t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and then:
Time t3 = addTime ( t1 , t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That works.
But with Operator Overloading, we can write:
Time t3 = t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This looks much more natural.
We are making our custom objects behave more like the built-in types we already know.
๐ข Part 4 โ Unary vs Binary Operators
Before writing the operator functions, we need to understand one simple question:
How many operands are involved?
Binary Operator
A binary operator works with two operands .
Example:
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Visual:
+
/ \
t1 t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There are two operands.
Therefore:
2 operands โ Binary operator
Other examples:
t1 - t2 ;
t1 = t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Unary Operator
A unary operator works with one operand .
Example:
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Visual:
++
|
t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There is only one operand.
Therefore:
1 operand โ Unary operator
Examples:
++ t1 ;
-- t1 ;
t1 ++ ;
t1 -- ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ง Easy Rule
Remember this:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 2 operands โ BINARY โ
โ 1 operand โ UNARY โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That's enough to classify the operators we are using.
โ Part 5 โ operator+()
Now let's finally overload +.
We want this:
Time t3 = t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
to work.
So we define:
Time Time :: operator + ( const Time & t )
{
Time temp ;
temp . hours = hours + t . hours ;
temp . minutes = minutes + t . minutes ;
temp . hours = temp . hours + temp . minutes / 60 ;
temp . minutes = temp . minutes % 60 ;
return temp ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Don't try to memorize this.
We are going to take it apart piece by piece .
10. Understanding the Function Header
Look at:
Time Time :: operator + ( const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Break it into parts:
Time Time:: operator+ (const Time &t)
โ โ โ โ
return belongs operator parameter
type to Time being used object
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now let's understand every part .
11. The First Time
Time Time :: operator +
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The first Time is the return type .
What is a return type?
A function can produce a result.
For example:
int add ( int a , int b )
{
return a + b ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The result is an integer.
Therefore:
int
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is the return type.
Our operator function returns:
Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Why?
Because:
Time + Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
produces another Time.
For example:
2 hours 40 minutes
+ 1 hour 30 minutes
-------------------
4 hours 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The result is still a Time .
Therefore:
Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is the return type.
12. What Does Time:: Mean?
The symbol:
::
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is called the scope resolution operator .
It tells C++ which class something belongs to.
So:
Time :: operator +
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
The operator+ function belonging to the Time class.
Think:
Time
โ
class
โ
operator+
โ
belongs to Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
13. What Does operator+ Mean?
This part:
operator +
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
We are defining the behavior of the + operator.
Similarly:
operator -
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
defines -.
operator =
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
defines =.
operator ++
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
defines ++.
And so on.
14. Understanding (const Time &t)
Now look at:
( const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This is the parameter list .
A parameter is information that a function receives.
For example:
int add ( int a , int b )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
has:
a
b
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
as parameters.
Our function receives:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Let's understand each piece.
15. What Does Time Mean Here?
Look at:
Time t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This means:
t is of type Time.
Remember:
Time t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Create a Time object called t1.
Similarly, inside our function:
Time t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
t refers to a Time object received by the function.
16. What Does & Mean?
Here:
Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
the & means reference .
A reference is another name or alias for an existing object.
Instead of creating a completely separate copy of the object, the parameter refers to an existing object.
For our expression:
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
we can think of the call as:
t1 . operator + ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Inside the function:
t1
โ
current object
t2
โ
parameter t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So t refers to the second object.
17. What Does const Mean?
Now we have:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
const means:
We promise not to modify the object through this reference.
Why?
Because while calculating:
t1 + t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
we only need to read t2.
We don't want addition to change t2.
So:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
can be understood as:
"Give me a reference to another Time object. I only want to read it, not modify it."
โญ 18. Where Did t1 Go?
This is one of the most important ideas in understanding member operator functions.
Suppose we write:
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Because operator+ is a member function of Time, we can think of it as:
t1 . operator + ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now everything becomes easier to understand.
t1.operator+(t2)
โ โ
| |
current parameter
object t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
t1 โ current object
t2 โ parameter t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Inside the function:
hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means the hours belonging to the current object.
So we can mentally think:
hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
as:
t1 . hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And:
t . hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
t2 . hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This mental model is extremely important .
๐งฎ 19. Let's Actually Add Two Times
Suppose:
t1 = 2 hours 40 minutes
t2 = 1 hour 30 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We want:
2 h 40 m
+ 1 h 30 m
-----------
4 h 10 m
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
First we add the hours.
temp . hours = hours + t . hours ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The current object's hours:
t1.hours = 2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The parameter object's hours:
t2.hours = 1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
2 + 1 = 3
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
temp.hours = 3
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
20. Adding the Minutes
Next:
temp . minutes = minutes + t . minutes ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We have:
t1.minutes = 40
t2.minutes = 30
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
40 + 30 = 70
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now:
temp = 3 hours 70 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But this isn't the normal way we represent time.
We normally want minutes to be:
0 to 59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So we need to convert the extra minutes.
๐ 21. What Is Normalization?
We can call this process normalization .
Normalization simply means:
Convert a value into its proper or standard form.
For example:
3 hours 70 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
can be converted to:
4 hours 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
because:
70 minutes = 1 hour 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
22. Why Do We Use / 60?
The code says:
temp . hours = temp . hours + temp . minutes / 60 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Suppose:
temp.minutes = 70
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then:
70 / 60 = 1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Because these are integers, this is integer division .
We are interested in how many complete hours are contained inside 70 minutes.
The answer is:
1 complete hour
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
3 hours + 1 hour
=
4 hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
23. Why Do We Use % 60?
Next:
temp . minutes = temp . minutes % 60 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The % operator gives the remainder after division.
For example:
70 % 60 = 10
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
70 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
contains:
1 complete hour
+
10 minutes remaining
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
4 hours 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is our final answer.
24. Why Do We Create temp?
Look at:
Time temp ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Why are we creating another object?
Because we need a separate object to store the result .
We don't want:
t1 = 2:40
t2 = 1:30
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
to be changed when we calculate:
t1 + t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Instead:
t1 t2
โ โ
2:40 1:30
\ /
\ /
\ /
operator+
|
โ
temp
|
4:10
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
Time temp ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Create a temporary Time object that we can use to build the result.
25. What Does return temp Mean?
At the end:
return temp ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Give the calculated Time object back to the code that called the function.
Remember:
Time t3 = t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The flow is:
t1 + t2
โ
operator+()
โ
create temp
โ
calculate 4:10
โ
return temp
โ
t3 receives the result
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
t3 = 4 hours 10 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ 26. Complete operator+() Flow
The expression:
Time t3 = t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
can be mentally understood as:
Time t3 = t1 . operator + ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then:
t1
โ
current object
t2
โ
parameter t
operator+
โ
create temp
โ
add hours
โ
add minutes
โ
convert extra minutes
โ
return temp
โ
t3
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
If this flow is clear, you already understand the core idea of Operator Overloading.
โ Part 6 โ operator-()
Now let's understand subtraction.
Time Time :: operator - ( const Time & t )
{
Time temp ;
temp . hours = hours ;
temp . minutes = minutes ;
if ( temp . minutes < t . minutes )
{
temp . hours -- ;
temp . minutes = temp . minutes + 60 ;
}
temp . hours = temp . hours - t . hours ;
temp . minutes = temp . minutes - t . minutes ;
return temp ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Most of this is already familiar.
The main new idea is:
Borrowing
27. Why Is - Binary?
Look at:
t1 - t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There are two operands:
t1 - t2
โ โ
operand operand
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
- is a binary operator.
28. Why Do We Need Borrowing?
Suppose:
t1 = 3 hours 20 minutes
t2 = 1 hour 40 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We want:
3 h 20 m
-1 h 40 m
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But:
20 - 40
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
doesn't give us a valid positive minute value.
So we borrow one hour.
Remember:
1 hour = 60 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
3 hours 20 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
becomes:
2 hours 80 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now:
80 - 40 = 40 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and:
2 - 1 = 1 hour
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Final:
1 hour 40 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
29. The Borrowing Code
if ( temp . minutes < t . minutes )
{
temp . hours -- ;
temp . minutes = temp . minutes + 60 ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Let's read it like a human.
First:
if ( temp . minutes < t . minutes )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
If the minutes we currently have are smaller than the minutes we want to subtract...
Then:
temp . hours -- ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Take one hour away.
For example:
3 hours
โ
2 hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then:
temp . minutes = temp . minutes + 60 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Convert that borrowed hour into 60 minutes.
So:
20 minutes + 60 minutes
=
80 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Now the subtraction can continue.
30. Complete Subtraction
After borrowing:
temp . hours = temp . hours - t . hours ;
temp . minutes = temp . minutes - t . minutes ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For:
2 h 80 m
-1 h 40 m
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
we get:
2 - 1 = 1 hour
80 - 40 = 40 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Final result:
1 hour 40 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฐ Part 7 โ Assignment Operator =
Now let's understand:
t1 = t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This means:
Copy the data from t2 into t1.
We can overload it:
Time & Time :: operator = ( const Time & t )
{
if ( this != & t )
{
hours = t . hours ;
minutes = t . minutes ;
}
return * this ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
31. Why Is = Binary?
Look at:
t1 = t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There are two operands:
t1 = t2
โ โ
operand operand
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
= is a binary operator.
๐งญ 32. What Does this Mean?
Now we encounter:
this
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Inside a member function, this is a pointer to the current object .
Suppose:
t1 = t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is being handled by:
operator =
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then:
current object โ t1
other object โ t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
this
โ
t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
In simple words:
this tells us which object is currently calling the member function.
33. What Does *this Mean?
If:
this
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
is a pointer to the current object, then:
* this
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means the actual current object .
Think:
this
โ
address of current object
*this
โ
actual current object
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
return * this ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Return the current object.
34. Why Do We Check this != &t?
The code contains:
if ( this != & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This checks for self-assignment .
For example:
t1 = t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Here the left and right objects are the same.
We don't need to copy an object onto itself.
So the condition asks:
"Is the current object different from the object being assigned?"
If yes, perform the copy.
35. Why Does operator= Return Time&?
Notice:
Time &
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
instead of:
Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The & means the function returns a reference to the existing Time object.
Returning a reference allows assignment expressions to behave naturally and supports expressions such as:
t1 = t2 = t3 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For a beginner, remember:
Time& means we return the existing Time object by reference instead of creating another separate object.
โฌ๏ธ Part 8 โ Prefix ++
Now let's move to unary operators.
Suppose:
t1 = 2 hours 59 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We want:
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
to increase the time by one minute.
We define:
Time & Time :: operator ++ ()
{
minutes ++ ;
if ( minutes >= 60 )
{
minutes = 0 ;
hours ++ ;
}
return * this ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
36. Why Is ++ Unary?
Look at:
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Visual:
++
|
t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Only one operand exists.
Therefore:
++ is a unary operator.
37. What Does minutes++ Mean?
Inside the function:
minutes ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Increase the current object's minutes by one.
If:
minutes = 40
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
then:
minutes = 41
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
If:
minutes = 59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
then:
minutes = 60
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But normal time representation doesn't keep 60 minutes.
So we need:
if ( minutes >= 60 )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
38. What Happens at 60 Minutes?
If:
minutes = 60
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
we do:
minutes = 0 ;
hours ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
2 hours 60 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
becomes:
3 hours 0 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
2:59
โ
++t1
โ
3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
39. What Is Prefix?
Prefix means the operator appears before the object:
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The basic idea is:
CHANGE FIRST
โ
USE NEW VALUE
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For example:
Before โ 2:59
++t1
After โ 3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So prefix returns the updated object.
That's why we use:
return * this ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
โฌ๏ธ Part 9 โ Postfix ++
Now look at:
t1 ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
It is also unary, but its behavior is different.
The implementation is:
Time Time :: operator ++ ( int )
{
Time temp = * this ;
minutes ++ ;
if ( minutes >= 60 )
{
minutes = 0 ;
hours ++ ;
}
return temp ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
40. Why Does Postfix Have int?
This is one of the most confusing parts for beginners.
Compare:
operator ++ ()
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and:
operator ++ ( int )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The int is a dummy parameter .
It is used to distinguish the two forms.
operator++()
โ
PREFIX
operator++(int)
โ
POSTFIX
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The int is not used to perform the increment .
It exists so C++ can distinguish prefix and postfix versions.
41. Why Do We Need temp for Postfix?
Suppose:
t1 = 2:59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
When we write:
t1 ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
postfix means:
Use the old value first, then change the object.
So first:
Time temp = * this ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Remember:
* this
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means the current object.
Therefore:
temp = 2:59
t1 = 2:59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then we increment the original object:
t1 = 3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But postfix needs to return the old value .
So:
return temp ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
returns:
2:59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Final situation:
Returned value = 2:59
Current t1 = 3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
42. Prefix vs Postfix
This is one of the most important things to remember.
Prefix
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
OLD VALUE
โ
CHANGE
โ
NEW VALUE
โ
RETURN NEW VALUE
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Postfix
t1 ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
OLD VALUE
โ
SAVE OLD VALUE
โ
CHANGE ORIGINAL
โ
RETURN OLD VALUE
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ง Easy memory trick
Prefix โ change first
Postfix โ save/use old value first
โฌ๏ธ Part 10 โ Prefix --
The same basic idea applies to decrement.
Time & Time :: operator -- ()
{
minutes -- ;
if ( minutes < 0 )
{
minutes = 59 ;
hours -- ;
}
return * this ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Suppose:
t1 = 3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Then:
-- t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
does:
3:00
โ
minutes becomes -1
โ
borrow from hour
โ
minutes = 59
hours = 2
โ
2:59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
43. Why Do We Check minutes < 0?
Normally minutes should stay between:
0 and 59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
If:
minutes = 0
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
and we subtract one:
minutes = -1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That's not a valid minute value.
So we convert:
3:00
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
into:
2:59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This is essentially the reverse idea of carrying an extra hour during addition.
โฌ๏ธ Part 11 โ Postfix --
The postfix version is:
Time Time :: operator -- ( int )
{
Time temp = * this ;
minutes -- ;
if ( minutes < 0 )
{
minutes = 59 ;
hours -- ;
}
return temp ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Again:
t1--
โ
save old value
โ
decrement original
โ
return old value
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Exactly the same pattern as postfix ++.
44. ++ and -- Summary
Expression
Type
Meaning
++t1
Unary
Prefix increment
t1++
Unary
Postfix increment
--t1
Unary
Prefix decrement
t1--
Unary
Postfix decrement
Remember:
Prefix:
change first โ return new value
Postfix:
save old value โ change โ return old value
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐จ๏ธ Part 12 โ Output Operator <<
Now let's understand one of the most confusing parts.
We already know:
cout << 10 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
prints:
10
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But what happens with:
Time t1 ;
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
C++ doesn't automatically know how to print our custom Time object.
So we define what << should do for Time.
ostream & operator << ( ostream & out , const Time & t )
{
out << t . hours << " hours "
<< t . minutes << " minutes" ;
return out ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
45. What Does cout << t1 Mean?
Think of:
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
as:
<<
/ \
cout t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
There are two operands:
cout
t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But there is an important difference from our earlier operators.
The left operand is:
cout
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
not:
Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That is why stream operators are commonly implemented as non-member functions .
46. What Is a Non-Member Function?
A non-member function is simply a function that does not belong to the class as a member function .
Our earlier function was:
Time Time :: operator + (...)
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Notice:
Time ::
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So it belongs to the Time class.
But:
ostream & operator << (...)
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
doesn't have:
Time ::
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
before it.
So it is a non-member function.
Why?
Because:
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
has:
left operand โ cout
right operand โ t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The left operand isn't a Time object.
47. What Is ostream?
ostream means:
Output Stream
cout is an output stream.
Therefore:
ostream & out
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
out is a reference to an output stream.
Inside the function:
out << t . hours ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
Send the hours to the output stream.
48. Why Is const Time &t Used for Output?
We have:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
because printing the object should only read its values .
We don't want:
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
to change:
t1.hours
t1.minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
OUTPUT
โ
read object
โ
don't modify it
โ
const Time&
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
49. Why Do We Return out?
At the end:
return out ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
This allows output chaining.
For example:
cout << t1 << t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
After printing t1, the stream is returned, allowing the next operation:
<< t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That's why stream output operators commonly return:
ostream &
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
โจ๏ธ Part 13 โ Input Operator >>
Now let's look at:
cin >> t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
We want the user to enter a time and store it inside the Time object.
So we overload >>:
istream & operator >> ( istream & in , Time & t )
{
cout << "Enter hours: " ;
in >> t . hours ;
cout << "Enter minutes: " ;
in >> t . minutes ;
t . hours = t . hours + t . minutes / 60 ;
t . minutes = t . minutes % 60 ;
return in ;
}
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
50. What Is istream?
istream means:
Input Stream
cin is an input stream.
Therefore:
istream & in
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
in is a reference to an input stream.
51. Why Is Time &t Used for Input?
Notice:
Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
not:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Why?
Because input needs to modify the object .
Suppose:
cin >> t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The user enters:
2
90
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The function needs to store these values inside t1.
Therefore:
cin
โ
input values
โ
modify Time object
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So the Time object cannot be const.
52. Why Does Input Normalize the Time?
Suppose the user enters:
hours = 2
minutes = 90
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The code:
t . hours = t . hours + t . minutes / 60 ;
t . minutes = t . minutes % 60 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
does:
90 / 60 = 1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
2 + 1 = 3 hours
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And:
90 % 60 = 30
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So:
2 hours 90 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
becomes:
3 hours 30 minutes
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ Part 14 โ << vs >>
A very easy way to remember them:
Output
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Think:
Time object
โ
goes OUT
โ
cout
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
<< โ OUTPUT
Input
cin >> t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Think:
cin
โ
data goes INTO
โ
Time object
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Therefore:
>> โ INPUT
๐บ๏ธ Part 15 โ Complete Operator Map
Now let's put everything together.
OPERATOR OVERLOADING
|
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ
โ โ โ
BINARY UNARY STREAM
| | |
+ - = ++ -- << >>
| | |
2 operands 1 operand input/output
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ Quick Reference Table
Operator
Example
Type
Function
+
t1 + t2
Binary
operator+()
-
t1 - t2
Binary
operator-()
=
t1 = t2
Binary
operator=()
++
++t1
Unary
operator++()
++
t1++
Unary
operator++(int)
--
--t1
Unary
operator--()
--
t1--
Unary
operator--(int)
<<
cout << t1
Stream
operator<<()
>>
cin >> t1
Stream
operator>>()
โญ Part 16 โ The Most Important Mental Model
If you remember only one thing from this entire article, remember this.
When you see:
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
think:
t1 . operator + ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
When you see:
t1 - t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
think:
t1 . operator - ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
When you see:
t1 = t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
think:
t1 . operator = ( t2 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
When you see:
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
think:
t1 . operator ++ ();
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
When you see:
t1 ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
think:
t1 . operator ++ ( int );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For output:
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
conceptually:
operator << ( cout , t1 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For input:
cin >> t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
conceptually:
operator >> ( cin , t1 );
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ง One Big Picture
Think of Operator Overloading like this:
t1 + t2
|
โ
"What should + do
for Time objects?"
|
โ
operator+()
|
โ
calculate
|
โ
return Time
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And for unary operators:
++t1
|
โ
operator++()
|
โ
change t1
|
โ
return result
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And for streams:
cout << t1
|
โ
operator<<()
|
โ
read Time object
|
โ
display
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
โ Part 17 โ Common Beginner Questions
โ Why can't I simply use t1 + t2?
Because C++ doesn't automatically know what + should mean for two objects of your custom Time class.
We define that behavior through Operator Overloading .
โ Why is + binary?
Because:
t1 + t2
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
contains two operands .
โ Why is ++ unary?
Because:
++ t1
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
contains one operand .
โ Why does postfix ++ have int?
Because C++ needs a way to distinguish:
operator ++ ()
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
from:
operator ++ ( int )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
The first represents prefix .
The second represents postfix .
โ What is this?
this is a pointer to the current object .
โ What is *this?
*this represents the actual current object .
โ Why is const used?
When we don't want a function to modify an object through a parameter.
For example:
const Time & t
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
means:
We can read the object, but we cannot modify it through t.
โ Why is & used?
It creates a reference .
A reference allows us to work with an existing object instead of creating another separate object.
โ Why do we need temp?
For + and -, temp is used to build and store the result .
For postfix ++ and --, temp is used to save the old value before changing the original object.
โ Why is output const?
Because output only needs to read the object.
โ Why isn't input const?
Because input needs to change the object and store the entered values inside it.
๐งช Part 18 โ Practice Questions
Before looking at the answers, try these yourself.
Question 1
Is this unary or binary?
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Question 2
Is this unary or binary?
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Question 3
Which function handles this?
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Question 4
Which function handles this?
t1 ++ ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Question 5
Why does postfix ++ have int?
Question 6
What does this represent?
Question 7
What does *this represent?
Question 8
Why do we use % 60?
Question 9
Which operator handles:
cout << t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Question 10
Which operator handles:
cin >> t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
โ
Answers
1. Binary
t1 + t2 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
has two operands.
Therefore:
Binary
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
2. Unary
++ t1 ;
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
has one operand.
Therefore:
Unary
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
3.
operator + ()
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
4.
operator ++ ( int )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
5.
The int is a dummy parameter used to distinguish postfix ++ from prefix ++.
6.
this is a pointer to the current object .
7.
*this represents the actual current object .
8.
To keep minutes within the normal range of:
0โ59
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
For example:
70 % 60 = 10
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
9.
operator << ()
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
10.
operator >> ()
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ Part 19 โ Final Cheat Sheet
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C++ OPERATOR OVERLOADING โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
BINARY
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
t1 + t2 โ operator+()
t1 - t2 โ operator-()
t1 = t2 โ operator=()
UNARY
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
++t1 โ operator++()
t1++ โ operator++(int)
--t1 โ operator--()
t1-- โ operator--(int)
STREAM
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
cout << t1 โ operator<<()
cin >> t1 โ operator>>()
IMPORTANT
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2 operands โ Binary
1 operand โ Unary
++t โ Prefix โ change first
t++ โ Postfix โ save old value first
--t โ Prefix โ change first
t-- โ Postfix โ save old value first
<< โ Output
>> โ Input
this โ pointer to current object
*this โ actual current object
const โ don't modify through this reference
& โ reference
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฏ Final Takeaway
Operator Overloading can look complicated when we first see:
Time Time :: operator + ( const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
But if we break it down:
Time
โ
return type
Time::
โ
belongs to Time class
operator+
โ
defines +
const
โ
don't modify the parameter
Time
โ
parameter type
&
โ
reference
t
โ
parameter name
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
Suddenly the declaration isn't so mysterious.
Then look at the body:
create result object
โ
add hours
โ
add minutes
โ
convert extra minutes
โ
return result
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
And the complete flow becomes:
t1 + t2
โ
t1.operator+(t2)
โ
operator+()
โ
calculate
โ
return Time object
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
That's the real idea behind Operator Overloading.
Don't memorize the syntax. Understand the relationship between the operator, the object, the function, and the result.
Once that mental model becomes clear, Operator Overloading stops looking like a collection of strange symbols and starts becoming a normal C++ concept.
๐ Complete Notes & Practice Material
If you want to go beyond this article, I've also organized the complete learning material in my GitHub repository.
It includes:
๐ Detailed beginner-friendly notes
๐จ Visual study notes
๐ป Complete C++ code
๐ Step-by-step concept explanations
๐งช Practice questions with answers
๐ Quick-reference / cheat sheets
๐ Explore the complete repository:
https://github.com/Poushmita/cpp_doubtClearance
You can use the repository alongside this article to read the concepts, explore the code, revise visually, and practice them yourself .
๐ญ Why I Like Learning This Way
This guide started with a simple situation: a friend asked me for help understanding Operator Overloading.
While explaining it, I realized that sometimes a concept feels difficult not because the concept itself is extremely complicated, but because too many small things are assumed to be already understood .
A beginner may understand Time but not Time&.
They may understand ++ but not why:
operator ++ ( int )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
contains int.
They may understand cout but not why:
ostream & operator << ( ostream & out , const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
looks different from:
Time Time :: operator + ( const Time & t )
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
๐ฅ Jadwal & Hasil: poushmita paul fddcbeaf/c operator overloading explained from zero a complete beginner friendly guide with a time cke - Info Live Streaming 2026
So I decided to write these notes with one simple rule:
Don't just explain what the code does. Explain why the code is written that way.
If you're learning C++ and Operator Overloading has ever felt confusing, I hope this guide helps you understand it one small piece at a time .
And if you're helping someone else learn it, feel free to use these notes as a teaching resource. โค๏ธ
If you find something that could be explained more clearly, feel free to suggest an improvement.
Top comments (2)
A very thorough beginner tutorial. A lot of work has gone in to this. We tend to lack material at this level for C++. Good stuff.
Thank you so much! ๐ I originally created this while helping a friend who was struggling with Operator Overloading. I tried to explain it the way I would explain it verbally โ breaking down even the small details that are usually skipped.
Really glad the beginner-friendly approach was useful. Thanks for reading! ๐