Define A Copy Constructor To Create A Deep Copy Of An Object | C++ Tutorial

Поділитися
Вставка
  • Опубліковано 17 гру 2024

КОМЕНТАРІ • 52

  • @ieduardoms
    @ieduardoms 2 роки тому +11

    Two weeks ago I was watching another channel for learning C++, the other channel was good, but THIS CHANNEL IS WAYS BETTER. Very well explained, thank you so much.

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      Thank you for being so supportive Eduardo, I'm glad you've found the C++ videos on this channel to be helpful. :-)

  • @WeirdGoat
    @WeirdGoat 8 днів тому

    Oh Man, you're so great at teaching! No nonsense at all, just directly goes into the knowledge we need!

  • @otheusma
    @otheusma Рік тому +1

    everytime i dont fully understand some new concept, i come to this channel and everything starts to make sense!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +2

      That's awesome Matheus, that makes me very happy to hear that the channel is helpful for you, thanks so much for sharing this! :-)

  • @punchline1729
    @punchline1729 2 роки тому +3

    I subed
    The pace and tone of these tutorials are pretty good, the information penetrates my brain when I watch them

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      That’s awesome to hear, and welcome aboard! :-)

  • @ValliNayagamChokkalingam
    @ValliNayagamChokkalingam Рік тому +2

    Thanks a ton! Your students are lucky to have an amazing professor like you!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      You're welcome Valli-Nayagam, and thank you for the kind words! :-)

  • @amrrasslan4329
    @amrrasslan4329 2 місяці тому

    every time i want to revise this topic i end up here thank you so much

  • @dwivedys
    @dwivedys 6 місяців тому

    Deep copy and Shallow copy concept sorted! Thank you!

  • @dashdroptv
    @dashdroptv 2 роки тому +2

    Very thorough explanation with great examples. Thanks for clarifying!

  • @semihaturkoglu
    @semihaturkoglu 4 місяці тому

    don't be bored telling the same thing: you're the best instructor

  • @papertowers4216
    @papertowers4216 2 роки тому +3

    This was extremely helpful and clear thank you so much.

  • @austinyu7404
    @austinyu7404 Рік тому

    I love u holy moly i was realy scratching my head on copy constructors

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      I'm glad to hear this video helped you out Austin! :-)

  • @KaLaka16
    @KaLaka16 2 роки тому +1

    Thanks a lot, this helped me solve a programming exercise i was stuck at.

  • @Anonymous-bu5bg
    @Anonymous-bu5bg Рік тому +1

    Excellent explanation!!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      I'm glad you enjoyed it! :-)

    • @Anonymous-bu5bg
      @Anonymous-bu5bg Рік тому

      @@PortfolioCourses do you have whole video like this on oops?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      No, right now I just have videos in the C++ Tutorial playlist covering lots of different OOP concepts. One day I would like to make a whole video covering OOP in C++ that is more of a "full course".

  • @jixuancheng
    @jixuancheng Рік тому

    @2:17 num2=num1; is using copy assignment operator function, instead copy construct. num2(num1) is using copy construct in my knowledge. That’s very confusing. But concept must be right.

  • @drankkkkkk
    @drankkkkkk 2 роки тому +1

    Excellent video!

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      I’m glad you enjoyed it, and thank you very much! :-)

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 роки тому

    great explanation, thank you

  • @emfahmi18
    @emfahmi18 2 роки тому

    This is so helpful, thank you so much

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      You're welcome! 🙂 Thank you for letting me know it was helpful for you.

  • @keblinskiwastaken
    @keblinskiwastaken Рік тому

    I did not receive any errors when the exit() was removed. Should I be worried if I dont receive errors or is it just depending on the software? I use vscode.

  • @isaackanda816
    @isaackanda816 2 роки тому

    thanks very much brother man🙌

  • @kevinliao9938
    @kevinliao9938 2 роки тому

    Really helpful
    Thanks

  • @itsmaxim01
    @itsmaxim01 11 місяців тому +1

    I get why you’re using malloc and free in this case (ie to throw the error) but really you should mention this is not considered good practice (and mention new/delete/smart pointers)

  • @makaty9883
    @makaty9883 Рік тому

    thx alot!

  • @ibrahimmalik4590
    @ibrahimmalik4590 Рік тому

    instead of malloc statement can we use new keyword?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      Yes Ibrahim. :-) I used malloc() in this video thinking that many programmers would be coming from C and may be more familiar with it, but a "C++ way" of doing it would be to use new instead.

  • @shafayet0198
    @shafayet0198 Рік тому

    why is const have been used in "Number(const Number &otherNumber)"

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      Great question Akash! :-) Because we will not modify otherNumber, we just use it to make the copy. It would be a mistake if we did. So we help enforce this with the language feature const.

  • @abdellahguennioui1568
    @abdellahguennioui1568 Рік тому

    hello, first i would to thank you for this tutorial, i do exactly the same thing in my computer but the deep copy he dosen't work, can you help me?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      You're welcome Abdellah! :-) The code in this video is found here, does using this exact code help resolve the issue? github.com/portfoliocourses/cplusplus-example-code/blob/main/copy_constructor.cpp

    • @abdellahguennioui1568
      @abdellahguennioui1568 Рік тому

      @@PortfolioCourses thank you so much for your videos, it's very helpful, i searched on internet and it's working now, thank you.

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      @@abdellahguennioui1568 Awesome I'm glad to hear you got it working, and you're welcome Abdellah! 🙂

  • @Vichained
    @Vichained 2 роки тому

    whts the diff between new and malloc?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      One day I'm going to make a video on dynamic memory allocation in C++. :-) The big difference is whether the constructor/destructor is called or not though, this might be helpful in the meantime: www.geeksforgeeks.org/new-vs-malloc-and-free-vs-delete-in-c/

    • @Vichained
      @Vichained 2 роки тому

      @@PortfolioCourses i know what dynamic memory allocation is. What you mean is that when you use New keyword you have to use the delete in order to free the allocated memory, while in alloc it’s done automatically?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      @@Vichained No, with malloc and calloc you need to free the memory that's been allocated, it's not automatic. With new and delete, the constructor and destructor of any object will be executed, with malloc/calloc/free, the destructor and constructor will not be executed.

    • @Vichained
      @Vichained 2 роки тому

      @@PortfolioCourses ohhhh gotcha. Thanks kevin

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      @@Vichained You're welcome! :-D