C++ Copy constructors (beginner-friendly tutorial + practical examples)

  Рет қаралды 60,574

CodeBeauty

CodeBeauty

Күн бұрын

This is an OOP tutorial where I'll teach you about copy constructors in C++. After watching this video, you'll learn what is the purpose of copy constructors, understand how they work in-depth, as well as how to fix and avoid most common errors in your code caused by copy constructors.
I'll also share best practices and tips on how to write good Object-Oriented code, and we'll see some real-world examples and practical applications of copy constructors.
📚 Learn how to solve problems and build projects 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
🚀📈💻🔥 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.
👉 Download a 7-day free trial from the PVS-Studio website or get an exclusive 30-day fully functional license for free by entering the 'code_beauty' promocode or use this link:
bit.ly/PVS-StudioFreeCB1
☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. You can use the link below to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
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 - Explanation of the code that we will be using for this video
05:08 - Purpose of the copy constructor
05:51 - Common errors related to copy constructors
07:24 - Rules for implementing a copy constructor
08:51 - In-depth analysis of the copy constructor
12:57 - Visual representation of common Copy constructor errors
19:18 - 3 situations when a copy constructor is invoked
19:49 - Difference between Copy constructor and Assignment operator
25:59 - Learn programming with my Practical Programming course
Related videos:
Constructors 1: • C++ OOP (2020) - What ...
Constructors 2: • C++ OOP (2020) - What ...
Destructors: • Destructors in Program...
Dynamic arrays and Pointers: • C++ POINTERS (2020) - ...
Add me on other platforms for more educational content:
Instagram 📸 - / truecodebeauty
Twitter 🐦- / truecodebeauty
******CODE IS IN THE COMMENTS******

Пікірлер: 138
@CodeBeauty
@CodeBeauty Жыл бұрын
📚 Learn how to solve problems and build projects 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 🚀📈💻🔥 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. ****CODE FROM THE VIDEO IS BELOW**** #include using namespace std; class Book { public: string Title; string Author; float* Rates; int RatesCounter; Book(string title, string author) { Title = title; Author = author; RatesCounter = 2; Rates = new float[RatesCounter]; Rates[0] = 5; Rates[1] = 4; } ~Book() { delete[] Rates; Rates = nullptr; } }; int main() { Book book1("Millionaire Fastlane", "M.J. DeMarco"); Book book2("C++ Lambda Story", "Bartek F."); cin.get(); }
@satyad620
@satyad620 11 ай бұрын
8:05
@satyad620
@satyad620 11 ай бұрын
8:05
@satyad620
@satyad620 11 ай бұрын
😊 8:05
@user-ww2lc1yo9c
@user-ww2lc1yo9c 4 ай бұрын
I came here for the copy constructor but kept looking at the breasts. I wish I could see more of them. Is there a way to do that?
@dhrubajyotisarma6268
@dhrubajyotisarma6268 Жыл бұрын
I love how you explain c++❤ very clearly
@hilgicamala2520
@hilgicamala2520 Жыл бұрын
can't wait for your course, your videos are the best, after months of struggling to understand programming, i now understand everything with your videos, and i even won a coding competition thanks to you
@I-SOY-SMART
@I-SOY-SMART Жыл бұрын
cool! congrats!
@saybalroy8393
@saybalroy8393 8 ай бұрын
Hey!! Congratulation❤❤
@saybalroy8393
@saybalroy8393 8 ай бұрын
How on the earth you make your every elucidations too simple. I really appreciate it ❤
@aaronsj80
@aaronsj80 Жыл бұрын
Very good video. I always enjoy watching your videos and being reminded of concepts that I haven't used in c++ that I haven't used in a long time since at work I've only been working on VB projects.
@isthatamy1973
@isthatamy1973 2 ай бұрын
BIG thank you for making this video!!!! Your videos are so comprehensive. I hope you will continue making a lot more good content like this. You truly inspired me
@CodeBeauty
@CodeBeauty 2 ай бұрын
Thank you, I'm happy that my videos help, and I'm making new videos every week 😄😄
@nv9usb381
@nv9usb381 Жыл бұрын
love your videos saldina and i'm sure your practical programming course will be amazing as well, i can't wait for it and thanks for the discount
@ltmega1665
@ltmega1665 Жыл бұрын
I love the content and the person as well
@milkamilkica1935
@milkamilkica1935 Жыл бұрын
cant wait for your course saldina, I love your videos, they are the best
@manoking9619
@manoking9619 Жыл бұрын
Thanks for this video! Copy constructors was one of those things that was confusing for me. It's difficult to test for deallocated memory so I could never be sure whether or not I copied correctly without having memory leak.
@deanmorrison6254
@deanmorrison6254 Жыл бұрын
can't wait for your practical programming course saldina. i already signed in and i'm sure it will be amazing
@eugeneamoakwah278
@eugeneamoakwah278 Жыл бұрын
thanks very much, love your explanations. 👍🏿👍🏿
@diegoi1313
@diegoi1313 11 ай бұрын
Thank you, this video explained the topic with great detail compared to my textbook. I look forward to your future video uploads.
@naderhumood1199
@naderhumood1199 Жыл бұрын
I liove your channel......this is first class of work. Thank you v much .
@l.p.1967
@l.p.1967 Жыл бұрын
Amazing as always. thanks Saldina
@junwenshou344
@junwenshou344 Жыл бұрын
Thanks for your video. Absolutely want to hear more about assignment operator or the Big Three. Appreciate that if you can also talk about deep copy vs shallow copy.
@AkashdeepRawat
@AkashdeepRawat Жыл бұрын
Best C++ tutorials
@naderhumood1199
@naderhumood1199 Жыл бұрын
Lovely channel... it's a value. Thank you very much indeed.....
@tofiq62
@tofiq62 Жыл бұрын
Thank you for your videos. It helps a lot!
@874D8
@874D8 2 ай бұрын
Fantastic and to the point. Thank you!
@johnniewalkerjohnniewalker2459
@johnniewalkerjohnniewalker2459 Жыл бұрын
Nice explanation of copy constructor!!
@fredofred8530
@fredofred8530 Жыл бұрын
Thanks! Nice to See you again. Greetings from Frankfurt/Main
@Hello33441
@Hello33441 Жыл бұрын
Please make a video on assignment operator!
@Nibyyy816
@Nibyyy816 Жыл бұрын
your channel best on youtube related to programming.
@danny12345
@danny12345 Жыл бұрын
Thank you for your time
@sujalthakkar2118
@sujalthakkar2118 2 ай бұрын
Tricky, yet simple. Only because of your explanations. 💗💗
@eugeneamoakwah278
@eugeneamoakwah278 Жыл бұрын
will want to know more about assignment operator as well.
@dundyd3612
@dundyd3612 Жыл бұрын
your videos helped me to finish university, I'm waiting for your practical programming course now to crash my internship. sending love for you codebeauty
@bojansekutkovski9696
@bojansekutkovski9696 Жыл бұрын
Great example, thanks
@kates-creates
@kates-creates 7 ай бұрын
i really love your videos! thank you for the content : D
@user-fe2bm1zy8p
@user-fe2bm1zy8p 5 ай бұрын
it was an incredible section thank you very well for your efforts you are the best teacher that I ever seen
@Tiger1AuasfE
@Tiger1AuasfE Жыл бұрын
Very nice Saldina.
@nikhilbalotra3675
@nikhilbalotra3675 Жыл бұрын
completed the whole playlist. Best way of explaining oops.
@maheshvelugula8418
@maheshvelugula8418 5 ай бұрын
Happy New year Madam, After a long time again I started to watch your videos😊😉
@CodeBeauty
@CodeBeauty 5 ай бұрын
Welcome back, and I also wish you a happy and prosperous 2024. 🥳🥳
@marym9003
@marym9003 Жыл бұрын
amazing video, thanks saldina
@gollygobih6527
@gollygobih6527 Жыл бұрын
thank you for this video dear saldina, when will your course be available, i already subscribed to the waiting list and i can't wait for it. love you so much, and thank you! 🥺❤
@KumarGaurav159
@KumarGaurav159 8 ай бұрын
It was really an awesome lecture on copy ctor, you cleared my all doubts in 1 go. i request you to please make a seprate video on copy assignment operator too, or diff b/w copy ctor and copy assignment operator!
@MessaoudBelgacem-py1ds
@MessaoudBelgacem-py1ds Жыл бұрын
I gave up programming in c++ years ago ... You gave me hope to rethink my decision ....
@bardial
@bardial Жыл бұрын
Awesome thanks ❤
@user-fs5rj2os9x
@user-fs5rj2os9x Жыл бұрын
Your explanation is marvelous, as a beginner, I have a better knowledge about copy constructor. Thanks and please keep going
@CodeBeauty
@CodeBeauty Жыл бұрын
🥰❤️
@arafathdhroba8897
@arafathdhroba8897 Жыл бұрын
you are too good!!
@sadeeque_moon
@sadeeque_moon Жыл бұрын
Well touch of cpp
@marekh2233
@marekh2233 Жыл бұрын
Ok. Very nice.
@jorgetorres1670
@jorgetorres1670 Жыл бұрын
Thanks.
@alexandruteodor3585
@alexandruteodor3585 Жыл бұрын
Thank you!
@oideaijen
@oideaijen Жыл бұрын
Very well explained! Thanks for the video. Would it be possible to make a video about move constructor? Thanks!
@nawalnajam2406
@nawalnajam2406 Жыл бұрын
I 💕💕 your videos on c++
@psk9736
@psk9736 8 ай бұрын
Life saviour ❤❤❤❤❤
@alexfrozen
@alexfrozen Жыл бұрын
Thank you for your work. Love!)
@OkonmahRaphael
@OkonmahRaphael Жыл бұрын
U're amazing... U just make coding easy🥺❤️
@Kenforbes3
@Kenforbes3 Жыл бұрын
Thanks!
@CodeBeauty
@CodeBeauty Жыл бұрын
Thanks 🥰❤️
@mardiyonghasben1619
@mardiyonghasben1619 11 ай бұрын
thank you ....miss CodeBeauty Godbless you miss...
@urossreckovic1408
@urossreckovic1408 4 ай бұрын
Good explained! Do you have video or maybe you are going to prepare explanation of move constructors?
@abdulqudoos6935
@abdulqudoos6935 Жыл бұрын
Plz make a video on move constructor
@devmarboy4045
@devmarboy4045 Жыл бұрын
do you have any videos on object compositions?
@erikitter6773
@erikitter6773 9 ай бұрын
Appreciated. I think it would have been even more helpful not using pointers, but demonstrating how you still need to do the copy constructors with modern C++.
@codingtochangetheworld5495
@codingtochangetheworld5495 Жыл бұрын
what app you use for screen record and edit your youtube video
@user-su6mr6mv9l
@user-su6mr6mv9l 11 ай бұрын
Hi Saldina, I have already subscribed to you, and I want to copy assignment, move ctor and move assignment ctor video. Thank you for your hard work
@user-kz8hc6gr3x
@user-kz8hc6gr3x Жыл бұрын
Умная и очаровательная девушка!
@pavelkravchenko2810
@pavelkravchenko2810 Жыл бұрын
Cool, when unit testing and ndk? 👻, pls🙏
@mohankumarparamas
@mohankumarparamas Ай бұрын
have you created any video for assignment operator? Please can you share the link
@gower1973
@gower1973 Жыл бұрын
I think what you mean at min 12 is that you have a circular dependency, I already knew about that array trap, Can you do a follow up on the copy and move assignment operators
@jhon3991
@jhon3991 20 күн бұрын
@CodeBeauty Why the compiler does not implicitly provide a default copy constructor to make the `Book(Book)` work? see 11:25 of the video.
@MohamedSalah-zv8fs
@MohamedSalah-zv8fs 10 ай бұрын
Can you pls make a video about move constructor and move semantics its really hard topic for me to understand
@Ian-bb7vv
@Ian-bb7vv 8 күн бұрын
question: Book 3; book 3 = b1; // this invokes the copy constructor right? thank you for the great video
@mardiyonghasben1619
@mardiyonghasben1619 11 ай бұрын
I am from indonesia ...i like learn this is chanell CodeBeauty ...
@AbhishekKumar-kk6qs
@AbhishekKumar-kk6qs 11 ай бұрын
Could you pls make some videos on visual studio for developers so that they can be efficient while debugging and development.
@bingolive3240
@bingolive3240 Жыл бұрын
yes I searched a lot for the copy constructor why we use the reference in the argument of the copy constructor instead of the simple object .. but this video is really very good to understand it … thank you so much .. and please make the video on the assignment operator and the copy constructor in detail....please
@bashiraddean-mufarreh
@bashiraddean-mufarreh Жыл бұрын
I'm waiting for explain static members and functions please if you don't mind 🙏
@jhon3991
@jhon3991 20 күн бұрын
@CodeBeauty Why the compiler not implitly provide a default copy ctor while there is only a custom constructor and a `Book(Book)` method is defined? If the compiler does so, the `Book(Book)` should work. See 11:25 of the video.
@fredofred8530
@fredofred8530 Жыл бұрын
Hello saldina, please make an tutorial about constructor. Especial about konfig list. There are Things beyond assigning init values to member values and simple heritage . What does the Compiler do with Text between colon and curly bracket in Detail. I really found nothing about this speaking to me. Thanks a lot!!!! Manfred
@lumberjackdreamer6267
@lumberjackdreamer6267 2 ай бұрын
Error: the argument to a copy constructor must be by reference. See standard in §12.8/3: A declaration of a constructor for a class X is ill-formed if its first parameter is of type (optionally cv- qualified) X and either there are no other parameters or else all other parameters have default arguments.
@jimpapay2895
@jimpapay2895 Ай бұрын
I would like to see the difference between copy constructor and assignment operator
@CodeBeauty
@CodeBeauty Ай бұрын
I'll publish that video next week 😄
@jimpapay2895
@jimpapay2895 Ай бұрын
Thank-you, I never knew that. Pretty important information to know.
@arthurmbogning9211
@arthurmbogning9211 Жыл бұрын
Hallo Saldina , thanks very much for your tutorial it Help me a lot to understand the concept behind. My question is about the call by value & reference. You Said call by value send the copy to the callee function or variable, that one is okay for me , but when it come to call by reference, due to the fact that it passed the original to a function. What will hapen if the callee function modify the original and that somewhere in the Code other functions need the original value that had been modify. This Situation give me nightmare when working with large functions 😢😢😢. Thanks very much for your Help.
@HuyTran-ew4yq
@HuyTran-ew4yq 9 ай бұрын
So to prevent the stuff you mentioned above, let use const keyword for the original.
@biniyamguadie
@biniyamguadie Жыл бұрын
please work hospital manegment system in c++
@pritampatil4163
@pritampatil4163 11 ай бұрын
how to do deep copy in this??@CodeBeauty
@mahdifrt202
@mahdifrt202 8 ай бұрын
a7ssen osstada f l3alam
@user-hq2pc5yz6p
@user-hq2pc5yz6p 6 ай бұрын
Wlah nadia
@BasitCeviriler
@BasitCeviriler 2 ай бұрын
How do you not have the default constructor? When I didn't my code have errors.
@CodeBeauty
@CodeBeauty 2 ай бұрын
If you need a parameterles constructor but you don't have it, you'll get errors 😊
@BasitCeviriler
@BasitCeviriler 2 ай бұрын
@@CodeBeauty Isn't it essential?
@vvkbees6473
@vvkbees6473 Жыл бұрын
😻👍
@wilgarcia1
@wilgarcia1 Жыл бұрын
😻😻😻
@shanmugammayan6966
@shanmugammayan6966 10 ай бұрын
Saldina❤😍
@Nibyyy816
@Nibyyy816 Жыл бұрын
I want a video on data science.
@muhammadtahasarwar2110
@muhammadtahasarwar2110 Жыл бұрын
my friend says its like: Hard to focus on code but learning and entertainment side by side;
@_rishi_ranjan
@_rishi_ranjan 9 ай бұрын
😂 🤣 🤣
@thesoftwareproject5798
@thesoftwareproject5798 Жыл бұрын
You do explain very well. I have to say that. However, there is a missing part: copy constructor invokation during return by value. I guess the video was already too long.
@thilinamadushan2207
@thilinamadushan2207 8 ай бұрын
👍👍👍👍👍👍👍
@markknight5178
@markknight5178 Жыл бұрын
I dunno, I like the simplicity of just deleting the code that is causing my errors. 😂
@fernandosantos3576
@fernandosantos3576 Жыл бұрын
Error exception! Code not found! ;-)
@gonzalocorboleguizamo201
@gonzalocorboleguizamo201 Жыл бұрын
a real smart beauty 😍🥰🤩
@Timo-Epis
@Timo-Epis 11 ай бұрын
"Like this"
@jglg7238
@jglg7238 10 ай бұрын
i love what she is wearing
@user-hf5fp6ys5u
@user-hf5fp6ys5u 8 ай бұрын
very good video , but it's hard to focus on the code when i see u
@ted2704
@ted2704 Жыл бұрын
Very good video, however I was pleasantly distracted 😉
@muhammadtahasarwar2110
@muhammadtahasarwar2110 Жыл бұрын
😉😉
@ted2704
@ted2704 Жыл бұрын
@@muhammadtahasarwar2110 You know what I'm talking about 👍
@muhammadtahasarwar2110
@muhammadtahasarwar2110 Жыл бұрын
@@ted2704 Oranges are pleasent and inviting especially in Summer; so yes they can be distracting
@user-ng2fp2ex3d
@user-ng2fp2ex3d 5 ай бұрын
💋😉
@mayankdubey6129
@mayankdubey6129 Жыл бұрын
Watched 2 times but only focused on two things
@curious_one1156
@curious_one1156 Жыл бұрын
I usually watch tutorial videos in 2x. Not this one though ;)
@solomonkassahun7845
@solomonkassahun7845 Жыл бұрын
Ohh shit i could not concentrate
@crazymemes4080
@crazymemes4080 2 ай бұрын
Coz of two parameters ?
@sihamtenho6433
@sihamtenho6433 2 ай бұрын
​@@crazymemes4080 😅😅😅
@subbuk9716
@subbuk9716 2 ай бұрын
Always looking at right corner..!!!!
@gaminglegend3313
@gaminglegend3313 Ай бұрын
​@@crazymemes4080 2 big reasons to watch her videos
@TheodorusAtheist-sx1un
@TheodorusAtheist-sx1un 5 күн бұрын
Me too 😂😂😂
@DART2WADER
@DART2WADER Жыл бұрын
Line 16 - bad idea.
@amac0612
@amac0612 2 ай бұрын
OF?
@benice9968
@benice9968 11 ай бұрын
distraction...
@CodeBeauty
@CodeBeauty 11 ай бұрын
you're easily distracted
@NoName-mq2jm
@NoName-mq2jm Жыл бұрын
nice dress bb gurl
Destructors in Programming: Practical Demonstration
20:10
CodeBeauty
Рет қаралды 30 М.
Copying and Copy Constructors in C++
20:52
The Cherno
Рет қаралды 418 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 102 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 58 МЛН
Китайка и Пчелка 10 серия😂😆
00:19
KITAYKA
Рет қаралды 2 МЛН
What are header files in C++ ( PROGRAMMING TUTORIAL for beginners)
23:54
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
Friend functions and classes in C++ (Programming for beginners)
18:18
C++ class copy constructor  [3]
8:13
Professor Hank Stalica
Рет қаралды 2,9 М.
Why I like C programming more than Web Dev (rant)
3:57
NeetCodeIO
Рет қаралды 139 М.
Define A Copy Constructor To Create A Deep Copy Of An Object | C++ Tutorial
17:06
Cadiz smart lock official account unlocks the aesthetics of returning home
0:30
TOP-18 ФИШЕК iOS 18
17:09
Wylsacom
Рет қаралды 639 М.
Интереснее чем Apple Store - шоурум BigGeek
0:42
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 1,1 МЛН
Mem VPN - в Apple Store
0:30
AndroHack
Рет қаралды 85 М.