Тёмный

Difference between copy constructor and assignment operator in C++ (OOP tutorial for beginners) 

Подписаться
Просмотров 6 тыс.
% 270

In this programming tutorial, we will learn the difference between an assignment operator and a copy constructor in C++. I'll teach you how to use an assignment operator as well as how to use a copy constructor. We will also learn some common mistakes that developers make when working with assignment operators and copy constructors. It is crucial that you understand the difference between these two so that you don't make any bugs while using them.
Enjoy the video and leave your questions in the comment section.
If you want to gain more practical experience in building real apps and get career-ready skills, join my Practical Programming Course below.
🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
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.
📚 Learn programming with these Free E-Books ⬇
C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
Download Visual Assist here: bit.ly/WT-CB
I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
Download Ultra Edit here: bit.ly/UE-CB
It is a powerful, secure text editor designed specifically for programmers.
Related videos:
Operator overloading in C++ - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-BnMnozsSPmw.html
Copy constructor in C++ - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-UYYoq784pQY.html
CONTENTS:
00:00 - Assignment operator VS copy constructor
01:06 - Where to learn practical programming
03:19 - Explaining the startup code
06:15 - How we use the copy constructor
11:10 - How we use the assignment operator
15:36 - The most important difference between the assignment operator and copy constructor
22:44 - Working with pointers
Add me on:
Instagram 📸 - TrueCodeBeauty
Twitter 🐦- TrueCodeBeauty
*******CODE IS IN THE COMMENTS*******

Наука

Опубликовано:

 

7 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 57   
@CodeBeauty
@CodeBeauty 2 месяца назад
🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/ 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!💰Use this coupon to save 10% (CODEBEAUTY_YT10). Use it quickly, because it will be available for a limited time. 📚 Learn programming with these Free E-Books ⬇ C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook *****CODE FROM THE VIDEO***** #include using namespace std; class Movie { public: string Name; string Genre; float Rating; Movie(string name, string genre, float rating) { Name = name; Genre = genre; Rating = rating; } Movie() { Name = ""; Genre = ""; Rating = 0; } Movie(const Movie& original) { Name = original.Name; Genre = original.Genre; Rating = original.Rating; } Movie& operator=(const Movie& original) { Name = original.Name; Genre = original.Genre; Rating = original.Rating; return *this; } }; int main() { Movie movie1("The Dark Knight", "Action", 9.5); Movie movie2("The Lion King", "Animated", 8); Movie movie3; Movie movie4(movie1); movie4 = movie2; //movie4.operator=(movie2); Movie movie5 = movie1; movie5 = movie2; cin.get(); }
@christopherrice891
@christopherrice891 2 месяца назад
I've been waiting patiently for more coding videos in C++ and it looks like my patience is paying off because lookie here! A new C++ coding video🤗!! Thank You very much Saldina✌️!!
@CodeBeauty
@CodeBeauty 2 месяца назад
Hahaha, I'm happy to hear that. Welcome back to another C++ lesson 🥰❤️
@MJavadZallaghi
@MJavadZallaghi Месяц назад
Very good tutorial! Thank you.
@snehadey883
@snehadey883 2 месяца назад
I am very excited for this video🥰I like your C++ programming tutorials, it helps me very much💝
@CodeBeauty
@CodeBeauty 2 месяца назад
Happy to hear that! The video is out, hope you'll enjoy it 🥰
@amirhosseinmoghimzadeh5887
@amirhosseinmoghimzadeh5887 Месяц назад
it was very good please publish more videos on OOP
@yawsokpor3061
@yawsokpor3061 2 месяца назад
Hi Iike your teaching method, the way you explained the difference between copy constructor and assingment costructor is very interesting
@joebosah2727
@joebosah2727 2 месяца назад
Thanks, SN Shallow Copy and Deep Copy Rule of 3 (and the lesser known Law of the Big Two)
@dabbabimarwen7474
@dabbabimarwen7474 2 месяца назад
I Like The Way You Insist On Details I'd Like To See The Process Of Writing an object with A String Field In a Binary File : Save Method Good Continuation... ♥
@whitewolf4689
@whitewolf4689 Месяц назад
This is some high level content with low level programming! yess I know C++ is a high level programming language ok
@jimpapay2895
@jimpapay2895 2 месяца назад
Cool! Thank-you.
@CodeBeauty
@CodeBeauty 2 месяца назад
You're welcome!
@muhmedgamal5841
@muhmedgamal5841 5 дней назад
Gooooood😊
@fikirgunlugum
@fikirgunlugum 2 месяца назад
We are waiting, and happy that the content picture does not include sub-messages. 😂
@CodeBeauty
@CodeBeauty 2 месяца назад
The video is out. I hope you'll enjoy it 🥰
@ProgrammerSolver
@ProgrammerSolver 2 месяца назад
Great teacher, thank you so much, you have an easy explanation way i understand all what you say, much love for you Saldina, i hope i have enough money to pay for your course
@CodeBeauty
@CodeBeauty 2 месяца назад
You are so welcome, and I hope that you'll join us in the course. You'll learn how to build real apps and get experience so that you can start a successful career as a developer 😊🥰
@ProgrammerSolver
@ProgrammerSolver 2 месяца назад
I hope that too, but one day I will join I'm sure @@CodeBeauty ❤❤
@nicholaskomsa1777
@nicholaskomsa1777 2 месяца назад
It would make sense to also cover move constructor, move assignment operator, to be complete.
@CodeBeauty
@CodeBeauty 2 месяца назад
I have a few more videos about constructors, destructor, copy c-tor on my channel. They should be in C++ OOP playlist, I hope they help to explain more stuff 😄😄👋
@marquelamar
@marquelamar 2 месяца назад
Nice lesson! You look great today.
@CodeBeauty
@CodeBeauty 2 месяца назад
Thanks 😃
@naderhumood1199
@naderhumood1199 2 месяца назад
Thank you Saldina....vedio is graat and Your gorgeous.
@CodeBeauty
@CodeBeauty 2 месяца назад
My pleasure 😊
@jorgetorres1670
@jorgetorres1670 2 месяца назад
Thanks.
@CodeBeauty
@CodeBeauty 2 месяца назад
You're welcome
@chrishabgood8900
@chrishabgood8900 2 месяца назад
do you use either of these in your day job?
@CodeBeauty
@CodeBeauty 2 месяца назад
You'll probably not create copy c-tors and assignment operators every day, but you'll definitely use them daily in your work, so if you for example get a bug and you don't understand this in depth, you'll have no idea how to fix the bug and make your code work
@jhon3991
@jhon3991 Месяц назад
@CodeBeauty The assigment operator returns a reference to the Movie other then an address of Movie. How do you think about that? See 13:25, for detail. If I am wrong, please let me know.
@Zulu-xe9zm
@Zulu-xe9zm 2 месяца назад
We are waiting
@CodeBeauty
@CodeBeauty 2 месяца назад
The video is out now 😊🥰
@danielkoziarski8488
@danielkoziarski8488 2 месяца назад
I do not understand why initializer list has been omitted for the demonstrated constructors. 😢
@CodeBeauty
@CodeBeauty 2 месяца назад
I can not put everything in one video. It's already very long 😅😅
@samialvi4226
@samialvi4226 2 месяца назад
Are we going to build gui apps as well plsss!
@Muhammadaliofficial5
@Muhammadaliofficial5 Месяц назад
What is difference between constructors and structures
@CodeBeauty
@CodeBeauty Месяц назад
They are related concepts, but they don't represent the sam thing. Watch my video about structures, and you'll learn what structures are with examples 😊
@mauzaomin3872
@mauzaomin3872 2 месяца назад
Why not deleting the newActor to free up the memory?
@CodeBeauty
@CodeBeauty 2 месяца назад
newActor is just holding the address in memory, and in that memory, we have data that we need, so if we free that memory, we'll lose the data that we need
@jackschitt7783
@jackschitt7783 2 месяца назад
I'm here for clickbait. Nice hat! They say comments help the "algorithym". Done. Redundantly. :)
@CodeBeauty
@CodeBeauty 2 месяца назад
Hahah, they do, thanks for the comment 😄 🥰
@nevram0101
@nevram0101 2 месяца назад
👍
@CodeBeauty
@CodeBeauty 2 месяца назад
👋
@skykid1075
@skykid1075 Месяц назад
She is my lovely cat sweet girl ! only mine !!!!!!!! Please do more videos !!!!!!!! 😘😘😘😘😘😘😘😘😘😘😘😘😘 I LOVE YOU KISS KISS KISS KISS KISS LOOOOOOOOOOVE .
@CodeBeauty
@CodeBeauty Месяц назад
🥰🥰
@skykid1075
@skykid1075 Месяц назад
@@CodeBeauty 😘😘😘😘😘
@SDRicky
@SDRicky Месяц назад
Ur accent is damn cute 🥺
@CodeBeauty
@CodeBeauty Месяц назад
It's the first time someone says that to me. Thank you so much 🥰🥰
@artstechnology7809
@artstechnology7809 2 месяца назад
Dont speaks English not understand english. My favorite programming language of computers 😢😢😢
@CodeBeauty
@CodeBeauty 2 месяца назад
Your English is not bad 😊😊
@artstechnology7809
@artstechnology7809 2 месяца назад
@@CodeBeauty I really don't know English, I'm answering you with google translate. This science of programming attracts me so much that I want to practice it and learn it perfectly. But I don't know, this also prevents me from learning after you. 😥
@kitcat2449
@kitcat2449 29 дней назад
​@@artstechnology7809Try to see if chatGPT can help you as well. It can explain code blocks line by line and translates quite well to other languages!
@muatzdaw8283
@muatzdaw8283 2 месяца назад
I great video to a greater teacher 🤍
@CodeBeauty
@CodeBeauty 2 месяца назад
Thank you! 😃
@nicholaskomsa1777
@nicholaskomsa1777 2 месяца назад
While an assignment-copy is a "Deep Copy", moving is a "Shallow Copy". Shallow copy steals pointers rather than duplicate their contents. here you go: struct Movie { std::string title; int year; Movie() { std::cout