Nicely you have explained, covered major points. I have few points which I want to add here to make your content more beautiful. 1. usually when we create a dynamic memory for a user-defined data type using a new operator constructor is automatically called but when dynamic memory is allocated using malloc it dose not call to the constructor. but with your example after used malloc constructor is called. Reason: malloc is called inside new. first new is executed by the compiler and due to the new operator compiler its self call to constructor. This means the new operator only does memory creation, but the new keyword informs the compiler to call the constructor for the user-defined data type. 2. if we overload the delete operator inside the class then we declare as void operator delete( void *p, size_t sz); here the second argument says what size of memory you are going to deallocate
@RahulBhadana_cse6 жыл бұрын
Thank you very much for uploading this video.👍
@CppNuts6 жыл бұрын
You are welcome dude!!
@yogendragangwar97956 жыл бұрын
Your videos are very help full for interview, Excellent explanation
@CppNuts6 жыл бұрын
Thanks for your comment!! It helps a lot!! 😀
@sajidriyaz29334 жыл бұрын
Beautifully explained.
@CppNuts4 жыл бұрын
Glad it was helpful!
@sudhirpratapsingh57305 жыл бұрын
Thanks man, you saved my day .. nice explanation.
@rahul-patil3 жыл бұрын
11:23 When operator new and operator new[] (Array version) are doing the same task when there is a need to overload the new operator with array version? Thanks for a clear explanation.
@bharathupadhya5 жыл бұрын
very nice video bro..thanks for creating these videos..
@amritkanoi88043 жыл бұрын
11:23, you need to overload explicitly new[ ] when you are creating an array of non-primitive type objects
@sumedh_34574 жыл бұрын
Thanks a lot for the video
@CppNuts4 жыл бұрын
My pleasure
@KNT_193 жыл бұрын
Basic question. Why to overload new operator? If we have an user defined class, then why to overload new operator for that class? In any way, user defined class's constructor will be called and in constructor we do all initializations. Can you give sample code(for user defined class) where actual usage of overloading new is required.
@rajeshgowda68846 жыл бұрын
Very good explanation..superb
@CppNuts6 жыл бұрын
Thanks man!!
@feraudyh4 жыл бұрын
Can I use an overloaded delete/new pair to check I am not doing a double delete? One idea that comes to mind is to store the set of deleted pointers every time I do a delete, and use this to check if I am not trying to delete twice. However if I have a set of classes designed by others that do deletes, I am probably not overloading the delete that this library calls.
@CppNuts4 жыл бұрын
Smart pointers?
@feraudyh4 жыл бұрын
@@CppNuts I've got legacy code. I don't know much about the strategy of upgrading to smart pointers.
@rahulr93012 жыл бұрын
excellent video brother!!!!...Thanks much. i have one doubt can we return NULL from overloaded new operator??
@avishekdutta19014 жыл бұрын
*static_cast=val; what is the use of the two '*' symbol here... Plzz explain!!!!!!
@CppNuts4 жыл бұрын
Why int*p only int* is needed.
@hsaidinsan63454 жыл бұрын
Avishek Dutta This is because static_cast(p) will cast p to a pointer to int, and if you need to access its content (dereference it) you need to use * again, so it will be like this *(static_cast(p))= val;
@pradeepsandaruwan61184 жыл бұрын
@@CppNuts Sir, there is a error when deleting the dynamically allocated memory in a class, when delete is in the destructor in the same class eventhough we use the copy constructor?
@ravivemisetti2483 жыл бұрын
Thanks for the videos, I have few doubts 1. While overloading new, default cnstor not called, in case of delete it is called default destructor. 2. If I added virtual fun it is giving error. Please clarify if possible
@checheromo76696 жыл бұрын
Thanks for this video
@shashikant.jadhav296 жыл бұрын
very good explanation...
@CppNuts6 жыл бұрын
Thanks man!!
@vvpChannel31123 жыл бұрын
Hi Rupesh sir.. Can we allocate memory using malloc and deallocate using delete ?
@vikramm49674 жыл бұрын
only the first index is assigned as the given val in case of array, how to assign each and evey index of the array?
@vima90462 жыл бұрын
Hello! I am used to using c# and i am new in c++, can you (or someone here) explain me why after the constructor "Text(x=0)" you put ":x{x} {}"? What does this syntax mean?
@shubhamshakya47414 жыл бұрын
Please sir tell me a book of C++ or a website from where i can solve programs for practice??
@aashishgoyal14366 жыл бұрын
thanks a lot
@CppNuts6 жыл бұрын
Thanks for your comment Aashish Goyal, and welcome to my channel, keep learning!!
@aashishgoyal14366 жыл бұрын
@@CppNuts Thanks a lot Rupesh Sir. Ur videos have helped me a lot during c++ interviews
@CppNuts6 жыл бұрын
Great...
@ramkrushnashelke58944 жыл бұрын
How can i use both placement new and overload new operator?
5 жыл бұрын
Sir we are not casting void pointer to class. Than how it's working
@AbhijeeetKumarSrivastavakshiva3 жыл бұрын
what happens If I allocate with int *prt new int[n]; and delete ptr?? Will the n memory blocks be deleted or only one block will be deleted?
@CppNuts3 жыл бұрын
Yes it should delete only one.
@AbhijeeetKumarSrivastavakshiva3 жыл бұрын
@@CppNuts Thanks for your response :)
@yasirarafat99463 жыл бұрын
How can I get full course ?
@CppNuts3 жыл бұрын
Full course on?
@bhoomitraders15995 жыл бұрын
can you write the program without malloc and free functions....!!!!
@CppNuts5 жыл бұрын
Meaning??
@bhoomitraders15995 жыл бұрын
@@CppNuts how malloc and free works in our programs?
@aniketahir1014 жыл бұрын
then you should know system calls
@bhoomitraders15994 жыл бұрын
Yes I want to know Bout this. Could you please make a video with system calls
@thejask27654 жыл бұрын
@@CppNuts I thought new() & delete() or malloc() & free() has to be used correspondingly to allocate and deallocate memory from heap. But this following program surprises me. Can you explain how can this possible with utmost clarity and without using generalised statements like this, here, that, there , it , this pointer , which pointer , that pointer etc. Here goes program segment. // CPP program to demonstrate // Overloading new and delete operator // for a specific class #include #include using namespace std; class student { string name; int age; public: student() { coutname = name; this->age = age; } void display() { cout
Nothing happens magically there is a reason behind.
@CppNuts5 жыл бұрын
For what?
@umairalvi73825 жыл бұрын
@@CppNuts like you told the new operator calls the constructor magically.But anyway nice tutorial.However i have a query In the line:- Test *t=new Test(); The overloaded new will return the void pointer but the type of *t is Test.How it is possible and why it is not throwing any error ?
@srinu5715 жыл бұрын
@@umairalvi7382 my question is also same.. if you find answer please comment it
@aniketahir1014 жыл бұрын
@umair alvi . when u store void pointer into any pointer container or pointer variable, it gets implicitely typecasted into the type of pointer variable.
@umairalvi73824 жыл бұрын
@@aniketahir101 try to do this with malloc() you will get an error. Int *p=malloc(sizeof(int)); This will give you an error in c++ but not in C.In C implicit type casting is done here.