Rule Of Three And Rule Of Five In C++ Programming

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

Komentáře • 17

  • @xRen0x
    @xRen0x Před 3 lety +2

    The Corollary : The rule of zero states that we can avoid writing any custom copy/move constructors, assignment operators, or destructors by using existing types that support the appropriate copy/move semantics

  • @poganka45
    @poganka45 Před 3 lety

    been following your videos for a long time, and learned a great deal of stuff, thanks!

    • @CppNuts
      @CppNuts  Před 3 lety

      Thanks.. for the comment.

  • @ParvezKhanPK
    @ParvezKhanPK Před 3 lety +2

    Wish you explained all these with example.

    • @CppNuts
      @CppNuts  Před 3 lety +1

      Sure..
      Move constructor and move assignment operator are on the way.

  • @bittupandey6645
    @bittupandey6645 Před 3 lety

    ❤️️move constructor needed

  • @_rtdp_
    @_rtdp_ Před 3 lety +1

    Okie sir... If you have uploaded any video on Move Constructor and Move Assignment Operator then please share the link... 😁...

  • @smilemania5102
    @smilemania5102 Před 3 lety

    Nice 👍👍 sir

  • @ranajibghosh
    @ranajibghosh Před 3 lety

    Please discuss on move semantics.

  • @muhammadwahab3609
    @muhammadwahab3609 Před 3 lety

    I don’t understand why ! Let’s just consider i have heap allocated memory but if I don’t copy this* object to any other object, destruction will simple free that memory and I don’t need to write copy or = operator
    I could be missing some information
    I would love to know what !

    • @tiagolavarinhas2852
      @tiagolavarinhas2852 Před 3 lety +1

      Not completely sure, but I think that is considered best practice because if all operators are properly implemented you can use the class in any way you want without thinking about how the class is implemented. Or you may not use the copy assignment/constructor for now but after some time you can start using those operators without remembering that the operators weren't implemented. But if you don't really need them maybe the better option is to delete them.

    • @muhammadwahab3609
      @muhammadwahab3609 Před 3 lety

      @@tiagolavarinhas2852 thank you 😊

    • @WowPlusWow
      @WowPlusWow Před 2 lety

      ​@@muhammadwahab3609 because let's say you write some code that does not copy any objects. Then after a couple months pass you decide to refactor or add some code and end up copying those objects either using the copy constructor or the = operator. Now you have a destructor that deletes the pointer while you're using the the complier generated constructors, which only create shallow copies. You can see how this will cause issues when one of those copies gets deleted and the destructor will delete the shallow copy of the pointer that may be still referenced by other objects that are still active. TLDR: It makes code a lot more maintainable and expandable.

  • @pseudounknow5559
    @pseudounknow5559 Před 3 lety

    Can you please increase the audio because without headphones it's impossible to hear you.

    • @CppNuts
      @CppNuts  Před 3 lety

      Sometimes it happens.