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
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 !
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 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.
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
been following your videos for a long time, and learned a great deal of stuff, thanks!
Thanks.. for the comment.
Wish you explained all these with example.
Sure..
Move constructor and move assignment operator are on the way.
❤️️move constructor needed
Okie sir... If you have uploaded any video on Move Constructor and Move Assignment Operator then please share the link... 😁...
Nice 👍👍 sir
Keep watching
Please discuss on move semantics.
Sure, coming soon!!
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 !
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.
@@tiagolavarinhas2852 thank you 😊
@@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.
Can you please increase the audio because without headphones it's impossible to hear you.
Sometimes it happens.