C++ Operator Overloading beginner to advanced (in-depth explanation)

preview_player
Показать описание
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️

Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
It is a powerful, secure text editor designed specifically for programmers.

In this video, I'll explain C++ Operator Overloading from beginner to advanced and teach you about operator functions.
In C++ overloaded operators are functions with special names: the keyword "operator" followed by the symbol for the operator being defined (ex. operator+, operator-, operator==, etc.)

Which operators can be overloaded?
- Most operators can be overloaded, the exceptions are . (dot) :: ?: sizeof
There are two types of operator functions: global operator functions and member operator functions.
In the video, I'll teach you about both and I'll also demonstrate how to do operator overloading for the most important operators and explain common errors that happen with operator overloading

However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇

Contents:
00:00 - Intro
01:01 - This is how I analyze my code
01:54 - Introduction to operator overloading and operator functions in C++
07:29 - Ostream operator overloading (insertion operator)
18:12 - Overloading += operator
21:35 - Different types of operator functions (global vs member functions)
23:57 - Ostream operator overloading (insertion operator)
26:57 - Overloading -= operator
28:34 - C++ operator overloading common errors
34:16 - Results of the PVS-Studio code analysis

Follow me on other platforms:

*******CODE IS IN THE COMMENTS*******
Рекомендации по теме
Комментарии
Автор

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

#include <iostream>
#include<string>
#include<list>
using namespace std;

struct YouTubeChannel {
string Name;
int SubscribersCount;

YouTubeChannel(string name, int subscribersCount) {
Name = name;
SubscribersCount = subscribersCount;
}
bool operator==(const YouTubeChannel&channel) const{
return this->Name == channel.Name;
}
};
ostream& operator<<(ostream& COUT, YouTubeChannel& ytChannel) {
COUT << "Name: " << ytChannel.Name << endl;
COUT << "Subscribers: " << ytChannel.SubscribersCount << endl;
return COUT;
}
struct MyCollection {


void operator+=(YouTubeChannel& channel) {

}
void operator-=(YouTubeChannel& channel) {

}
};
ostream& operator<<(ostream& COUT, MyCollection& myCollection) {
for (YouTubeChannel ytChannel : myCollection.myChannels)
COUT << ytChannel << endl;
return COUT;
}

int main()
{
YouTubeChannel yt1 = YouTubeChannel("CodeBeauty", 75000);
YouTubeChannel yt2 = YouTubeChannel("My second channel", 80000);

MyCollection myCollection;
myCollection += yt1;
myCollection += yt2;
myCollection -= yt2;

cout << myCollection;

cin.get();
}

CodeBeauty
Автор

You somehow got me to understand a concept in 30 minutes where my professor couldn't for a whole semester
thank you so much for the videos. They're really carrying me through college!

tactlesscloud
Автор

We all loves this girl. She is amazing!

matijaxzivkovic
Автор

I spend hours watching your videos and every times I say "ohhhh that's why". You can't imagine how many times you explain me things that others never succeeded in teaching me.

remimonsel
Автор

It's at the midnight, a.m. 30, in Taiwan, and I will look this video in the morning!

e-sm
Автор

So far the best video I have found for operator overloading

barshachaudhary
Автор

You come up exactly with the topic that i look forward to learn. 😄🤘

siddharthpawar
Автор

every minute of this video is worth it,
thankyou beauty to help us enhance our coding skills...

I love the way how small and side error cases you taught with so much simplicity,
I have done 2 DSA courses till now, they had never given any importance to Operator Overloading,
just taught the syntax, told this is overloading, enjoy students!

anshulbansal
Автор

I've been studying computer science for almost 3 years and this is the first time I've truly understood this. Thank you.

claritydive
Автор

I haven't used c++ in years and these videos make for a great refresher on how things work. Also love when she says the work parameters

chriscarlin
Автор

Every seconds I watched, I learnt something new. Wonder how many more good people we have in this world. Thanks a lot!

jassielitu
Автор

Thanks very much for articulating the concept so clearly! I also appreciated that you explained (23:18) why, when overloading the << operator, we needed two parameters while the + operator only needed one!

oatie
Автор

cout << yt1;
Hmm, I think it is gonna return the address of the variable that stores the instantiated struct

granumuse
Автор

We can never get bored in your lectures! Your way of teaching is fab 😊

satvrii
Автор

Waiting!!!
I hope that's gonna be another fantastic video❣️

muhammadumair
Автор

You gave a great explanation of operator overloading. I especially appreciated the explanation of the errors at the end for the -= operator.

DON
Автор

Tommarow is my final term paper so I am so confused about operator overloading but after watching this video, now I so comfident... Thanks Mam your effort is priceless the way you teach programming is very amazing...Thanks for helping us. Big respect from pakistan..

aesthetic.__.writes
Автор

Wonderful! Awaiting for this very interesting topic! Thank you!!!

mexxiano
Автор

I watched so many videos on operator overloading, and i can confidently say this is hands down the **BEST** video on this topc, thank you so much for explaining it this clearly. made my day

deveshsingh
Автор

I've started learning from you when I'd looked for tutorial about maps but now I just can't stop studying different topics I discovered here. Programming became such a cool thing for me. I always find something new, see old topics in a new light and it's such a feeling... thank you so much!!! This June is amasing because of you^^

likami