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

Sdílet
Vložit
  • čas přidán 27. 08. 2024

Komentáře • 145

  • @CodeBeauty
    @CodeBeauty  Před rokem +26

    📚 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 Před rokem

      8:05

    • @satyad620
      @satyad620 Před rokem

      8:05

    • @satyad620
      @satyad620 Před rokem

      😊 8:05

    • @user-ww2lc1yo9c
      @user-ww2lc1yo9c Před 6 měsíci

      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?

  • @hilgicamala2520
    @hilgicamala2520 Před rokem +35

    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

  • @dhrubajyotisarma6268
    @dhrubajyotisarma6268 Před rokem +10

    I love how you explain c++❤ very clearly

  • @manoking9619
    @manoking9619 Před rokem +10

    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.

  • @saybalroy8393
    @saybalroy8393 Před 11 měsíci +3

    How on the earth you make your every elucidations too simple. I really appreciate it ❤

  • @isthatamy1973
    @isthatamy1973 Před 4 měsíci +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  Před 4 měsíci +1

      Thank you, I'm happy that my videos help, and I'm making new videos every week 😄😄

  • @AkashdeepRawat
    @AkashdeepRawat Před rokem +4

    Best C++ tutorials

  • @ltmega1665
    @ltmega1665 Před rokem +5

    I love the content and the person as well

  • @aaronsj80
    @aaronsj80 Před rokem +6

    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.

  • @naderhumood1199
    @naderhumood1199 Před rokem +2

    I liove your channel......this is first class of work. Thank you v much .

  • @dundyd3612
    @dundyd3612 Před rokem +1

    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

  • @deanmorrison6254
    @deanmorrison6254 Před rokem +3

    can't wait for your practical programming course saldina. i already signed in and i'm sure it will be amazing

  • @junwenshou344
    @junwenshou344 Před rokem +4

    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.

  • @johnniewalkerjohnniewalker2459

    Nice explanation of copy constructor!!

  • @l.p.1967
    @l.p.1967 Před rokem +4

    Amazing as always. thanks Saldina

  • @naderhumood1199
    @naderhumood1199 Před rokem +4

    Lovely channel... it's a value. Thank you very much indeed.....

  • @eugeneamoakwah278
    @eugeneamoakwah278 Před rokem +4

    thanks very much, love your explanations. 👍🏿👍🏿

  • @danny12345
    @danny12345 Před rokem +2

    Thank you for your time

  • @sujalthakkar2118
    @sujalthakkar2118 Před 4 měsíci

    Tricky, yet simple. Only because of your explanations. 💗💗

  • @fredofred8530
    @fredofred8530 Před rokem +1

    Thanks! Nice to See you again.
    Greetings from Frankfurt/Main

  • @eugeneamoakwah278
    @eugeneamoakwah278 Před rokem +3

    will want to know more about assignment operator as well.

  • @Hello33441
    @Hello33441 Před rokem +3

    Please make a video on assignment operator!

  • @nv9usb381
    @nv9usb381 Před rokem +4

    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

  • @nawalnajam2406
    @nawalnajam2406 Před rokem +4

    I 💕💕 your videos on c++

  • @milkamilkica1935
    @milkamilkica1935 Před rokem +1

    cant wait for your course saldina, I love your videos, they are the best

  • @Tiger1AuasfE
    @Tiger1AuasfE Před rokem +2

    Very nice Saldina.

  • @diegoi1313
    @diegoi1313 Před rokem +1

    Thank you, this video explained the topic with great detail compared to my textbook. I look forward to your future video uploads.

  • @874D8
    @874D8 Před 4 měsíci +1

    Fantastic and to the point. Thank you!

  • @maheshvelugula8418
    @maheshvelugula8418 Před 7 měsíci +2

    Happy New year Madam, After a long time again I started to watch your videos😊😉

    • @CodeBeauty
      @CodeBeauty  Před 7 měsíci

      Welcome back, and I also wish you a happy and prosperous 2024. 🥳🥳

  • @MessaoudBelgacem-py1ds

    I gave up programming in c++ years ago ... You gave me hope to rethink my decision ....

  • @OkonmahRaphael
    @OkonmahRaphael Před rokem +3

    U're amazing...
    U just make coding easy🥺❤️

  • @jorgetorres1670
    @jorgetorres1670 Před rokem +2

    Thanks.

  • @KumarGaurav159
    @KumarGaurav159 Před 11 měsíci +1

    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!

  • @suryakantkashyap2468
    @suryakantkashyap2468 Před měsícem

    Amazing Explanation!!

  • @user-fe2bm1zy8p
    @user-fe2bm1zy8p Před 8 měsíci

    it was an incredible section thank you very well for your efforts you are the best teacher that I ever seen

  • @marekh2233
    @marekh2233 Před rokem +2

    Ok. Very nice.

  • @alexfrozen
    @alexfrozen Před rokem +3

    Thank you for your work.
    Love!)

  • @Nibyyy816
    @Nibyyy816 Před rokem

    your channel best on youtube related to programming.

  • @muhammadtahasarwar2110
    @muhammadtahasarwar2110 Před rokem +4

    my friend says its like: Hard to focus on code but learning and entertainment side by side;

  • @gollygobih6527
    @gollygobih6527 Před rokem +2

    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! 🥺❤

  • @tofiq62
    @tofiq62 Před rokem +1

    Thank you for your videos. It helps a lot!

  • @nikhilbalotra3675
    @nikhilbalotra3675 Před rokem

    completed the whole playlist. Best way of explaining oops.

  • @user-fs5rj2os9x
    @user-fs5rj2os9x Před rokem +1

    Your explanation is marvelous, as a beginner, I have a better knowledge about copy constructor. Thanks and please keep going

  • @alexandruteodor3585
    @alexandruteodor3585 Před rokem +1

    Thank you!

  • @bojansekutkovski9696
    @bojansekutkovski9696 Před rokem

    Great example, thanks

  • @AbdullahGhamdi
    @AbdullahGhamdi Před rokem +2

    Thanks!

  • @arafathdhroba8897
    @arafathdhroba8897 Před rokem +1

    you are too good!!

  • @abdulqudoos6935
    @abdulqudoos6935 Před rokem +1

    Plz make a video on move constructor

  • @bingolive3240
    @bingolive3240 Před rokem +1

    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

  • @kates-creates
    @kates-creates Před 10 měsíci

    i really love your videos! thank you for the content : D

  • @jhon3991
    @jhon3991 Před 3 měsíci

    @CodeBeauty Why the compiler does not implicitly provide a default copy constructor to make the `Book(Book)` work? see 11:25 of the video.

  • @marym9003
    @marym9003 Před rokem

    amazing video, thanks saldina

  • @mardiyonghasben1619
    @mardiyonghasben1619 Před rokem +1

    thank you ....miss CodeBeauty Godbless you miss...

  • @urossreckovic1408
    @urossreckovic1408 Před 6 měsíci

    Good explained! Do you have video or maybe you are going to prepare explanation of move constructors?

  • @erikitter6773
    @erikitter6773 Před 11 měsíci

    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++.

  • @sadeeque_moon
    @sadeeque_moon Před rokem

    Well touch of cpp

  • @lumberjackdreamer6267
    @lumberjackdreamer6267 Před 5 měsíci

    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.

  • @jhon3991
    @jhon3991 Před 3 měsíci

    @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.

  • @oideaijen
    @oideaijen Před rokem

    Very well explained! Thanks for the video. Would it be possible to make a video about move constructor? Thanks!

  • @jimpapay2895
    @jimpapay2895 Před 3 měsíci +1

    I would like to see the difference between copy constructor and assignment operator

    • @CodeBeauty
      @CodeBeauty  Před 3 měsíci

      I'll publish that video next week 😄

    • @jimpapay2895
      @jimpapay2895 Před 3 měsíci

      Thank-you, I never knew that. Pretty important information to know.

  • @mohankumarparamas
    @mohankumarparamas Před 4 měsíci

    have you created any video for assignment operator? Please can you share the link

  • @mardiyonghasben1619
    @mardiyonghasben1619 Před rokem +1

    I am from indonesia ...i like learn this is chanell CodeBeauty ...

  • @user-kz8hc6gr3x
    @user-kz8hc6gr3x Před rokem

    Умная и очаровательная девушка!

  • @bardial
    @bardial Před rokem

    Awesome thanks ❤

  • @gower1973
    @gower1973 Před rokem

    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

  • @BasitCeviriler
    @BasitCeviriler Před 4 měsíci +1

    How do you not have the default constructor? When I didn't my code have errors.

    • @CodeBeauty
      @CodeBeauty  Před 4 měsíci

      If you need a parameterles constructor but you don't have it, you'll get errors 😊

    • @BasitCeviriler
      @BasitCeviriler Před 4 měsíci +1

      @@CodeBeauty Isn't it essential?

  • @devmarboy4045
    @devmarboy4045 Před rokem +1

    do you have any videos on object compositions?

  • @codingtochangetheworld5495

    what app you use for screen record and edit your youtube video

  • @psk9736
    @psk9736 Před 10 měsíci

    Life saviour ❤❤❤❤❤

  • @biniyamguadie
    @biniyamguadie Před rokem +1

    please work hospital manegment system in c++

  • @user-su6mr6mv9l
    @user-su6mr6mv9l Před rokem

    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

  • @HussaynSaed
    @HussaynSaed Před 2 měsíci +1

    i really can see ++

  • @Ian-bb7vv
    @Ian-bb7vv Před 2 měsíci

    question:
    Book 3;
    book 3 = b1; // this invokes the copy constructor right?
    thank you for the great video

    • @-aditheplatypus-9359
      @-aditheplatypus-9359 Před 2 měsíci

      The line "Book 3;" with the class example in the video called "Book" will create a book class named only 3, so it will give you an error when trying to assign it to b1. If the question you were reffering was with the code:
      Book book3;
      book3=b1;
      It would have invoked the copy constructor, even though it could have been written as "Book book3=b1;"

  • @SohngShin
    @SohngShin Před 2 měsíci

    why does c or c++ even pass by value? Why not pass by reference all the time? what is the benefit of passing by value?

  • @MohamedSalah-zv8fs
    @MohamedSalah-zv8fs Před rokem

    Can you pls make a video about move constructor and move semantics its really hard topic for me to understand

  • @AbhishekKumar-kk6qs
    @AbhishekKumar-kk6qs Před rokem

    Could you pls make some videos on visual studio for developers so that they can be efficient while debugging and development.

  • @fredofred8530
    @fredofred8530 Před rokem

    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

  • @nicholaskomsa1777
    @nicholaskomsa1777 Před 15 dny

    you should definately do a move constructor video
    for instance, a move constructor:
    class A {
    public:
    std::vector v;
    std::string str;
    std::mutex m;
    A() {
    v.resize(100);
    str.resize(100);
    }
    A( A&& a) noexcept {
    v = std::move(a.v);
    str = std::move(a.str);
    }
    void printAddresses() {
    auto print = [&](const auto& c, auto pointer) {
    std::cout

  • @markknight5178
    @markknight5178 Před rokem +1

    I dunno, I like the simplicity of just deleting the code that is causing my errors. 😂

  • @bashiraddean-mufarreh

    I'm waiting for explain static members and functions please if you don't mind 🙏

  • @pavelkravchenko2810
    @pavelkravchenko2810 Před rokem

    Cool, when unit testing and ndk? 👻, pls🙏

  • @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.

  • @mahdifrt202
    @mahdifrt202 Před 10 měsíci

    a7ssen osstada f l3alam

  • @Nibyyy816
    @Nibyyy816 Před rokem

    I want a video on data science.

  • @arthurmbogning9211
    @arthurmbogning9211 Před rokem

    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 Před 11 měsíci

      So to prevent the stuff you mentioned above, let use const keyword for the original.

  • @pritampatil4163
    @pritampatil4163 Před rokem

    how to do deep copy in this??@CodeBeauty

  • @fernandosantos3576
    @fernandosantos3576 Před rokem

    Error exception! Code not found! ;-)

  • @mayankdubey6129
    @mayankdubey6129 Před rokem +2

    Watched 2 times but only focused on two things

  • @ted2704
    @ted2704 Před rokem +1

    Very good video, however I was pleasantly distracted 😉

  • @user-hf5fp6ys5u
    @user-hf5fp6ys5u Před 11 měsíci

    very good video , but it's hard to focus on the code when i see u

  • @jglg7238
    @jglg7238 Před rokem

    i love what she is wearing

  • @shanmugammayan6966
    @shanmugammayan6966 Před rokem

    Saldina❤😍

  • @solomonkassahun7845
    @solomonkassahun7845 Před rokem +26

    Ohh shit i could not concentrate

  • @vvkbees6473
    @vvkbees6473 Před rokem +1

    😻👍

  • @wilgarcia1
    @wilgarcia1 Před rokem +1

    😻😻😻

  • @gonzalocorboleguizamo201

    a real smart beauty 😍🥰🤩

  • @Timo-Epis
    @Timo-Epis Před rokem

    "Like this"

  • @curious_one1156
    @curious_one1156 Před rokem

    I usually watch tutorial videos in 2x. Not this one though ;)

  • @shamveerapan2875
    @shamveerapan2875 Před 7 měsíci +1

    Really good explanation. But sis, wear a proper dress. You don't need to reply me, but change yourself. Everyone Please don't tell 'You came to learn not for anything else'😅😅

    • @1729krish
      @1729krish Před 4 měsíci +2

      Bro live and let live. Dont tell others what to do

    • @shamveerapan2875
      @shamveerapan2875 Před 4 měsíci

      @@1729krish ​yeah I understand. but got to say what I see. 😌😌😌😌

    • @cristinaciui7192
      @cristinaciui7192 Před 2 měsíci

      it's not even that revealing stfu

  • @thilinamadushan2207
    @thilinamadushan2207 Před 11 měsíci

    👍👍👍👍👍👍👍