Hello , I am using Visual Studio 2022 And when I type like your code 02:00 The Destructor does not activate!! But it becomes like a function being called by the object , Is it because of the Compiler or a new language update ? Or is there something wrong ?
@@snowandl4195 OK, so it sounds like you solved the issue on your own? Or is it still an issue? The code for this example is here, it should work: github.com/portfoliocourses/cplusplus-example-code/blob/main/destructor_basics.cpp
ones I run clear the g++ to compile it and now at the 3rd compilation I get this? [error: cannot convert ‘double*’ to ‘double’ in assignment 12 | number = (double *) malloc(sizeof(double));] - did you see any issues here in my line? Thank you first run all go but during the Video I enter 3lines more and then... :-( Thank you for this Video I'm a beginner in C++ I found the failure! private: double *number; //here I loose the * and then this Error occur
Hey, all great tutorial videos out there, thx! I want to ask that some videos are covered in C but not in C++, might due to the reason C++ tutorial is not done, so could I use those "missing" videos in C to cover the same concept in C++?like pointer, dynamic allocation, etc. Cause Im taking C++ course rn.
For the most part.... yes. C++ basically maintains compatibility with C for the most part. So if a program works in C, it will work in C++. But this is only "mostly" true, there are some small differences and exceptions here and there too. e.g. in C we can have: int *data = malloc(sizeof(int) * 50); but in C++ we need to have: int *data = (int) malloc(sizeof(int) * 50);
Sometimes we really should in order to “clean up” things that the object is responsible for cleaning up. Like if you delete a Person object and a Hand object is created and “owned” by that Person object from initialization until deletion then the Person object should delete it, for example.
For a basic double array it won't matter, but I suppose new learners watching this video might not know that or what malloc is either... maybe one day I'll make another destructor video using new instead.
@@PortfolioCourses Its not too hard to understand what it is doing, I just found it a wild contrast of the old C style and modern C++ tools. Though if going modern in a new video you should probably should just skip right to a unique_ptr or make_unique; new and delete have been superseded for over a decade [but yes they are still popular in the wild]
Smart pointers are pretty neat and something I want to cover as well. I’m not a big fan of how many ways it’s possible to do things in C++, I’ve come to prefer more opinionated languages and technologies like Python over the years.
@@PortfolioCourses The wide number of options is just a natural outcome of maintaining decades of backward compatibility. However most of those other options are essentially deprecated and only exist for that backward compatibility and occasionally some niche boilerplate use cases. That is, combining "C with Classes" features with C++20 features is technically possible but not the intended use; it would be like mixing Python 1, 2, 3, and cython into a mutant program. (If Python had backward compatibility.) The example here of dynamic allocation, the Core C++ guidelines that accompany the standard, consider new, and delete as completely outdated, with smart pointers being a zero overhead replacement everywhere except in the writing of the smart pointers. (They are implemented as library class templates, not core built ins.) Malloc and Free are not part of C++, they are C, isoC++ just happens to adopt most of IsoC for compatibility. (There are a couple C keywords that are not in a C++ compiler, and a few that emulate C but are different down deep.) So while C++ is permissive for those that need it to be, it is also quite opinionated.
@@mytech6779 I prefer opinionated technologies that are not permissive. I've never heard the term opinionated applied to a technology that is also permissive, that's interesting that a technology could be both at the same time. My issue with things being "essentially" deprecated is that we know people will use them anyways, whether they should or shouldn't.
Hey professor, it's look like many different ways made Destructor called. So when exactly is Destructor called? Or how many ways to make Destructor called? When an object goes out of the scope, when the program end, or when delete operator is called? I'm so confused right now.
It's definitely confusing, but yes, you're correct, those are the 3 main ways that a destructor is called: when the program terminates, when the scope containing the object ends, and when the delete operator is called. There are some other ways that a destructor can be called, for example if we are using inheritance in our program, that is covered in those videos. 🙂
@@PortfolioCourses Hi just reading the commnets- just another question - i understand that there are 3 main ways, how do you choose when do call the delete operator? Also, from what I understand, there is an implicit destructor in the class even if we don't write it, so if thats the case, when do we write one and when do we not?
I would say the main issue with pointers the fact they didn't work with them, for example i used to use cheat engine and that really helped me grasp pointers and assembly@@PortfolioCourses
you are a king of explanation
Thanks for providing the source code, this way we can open the source code and don't need to go back and forward in the video.
You're welcome Eduardo! :-)
Super clear explanations. Thank you!!
You're welcome Thea! 😀
Hello , I am using Visual Studio 2022
And when I type like your code 02:00
The Destructor does not activate!!
But it becomes like a function being called by the object , Is it because of the Compiler or a new language update ? Or is there something wrong ?
Sorry to bother you, I was using this code at the bottom of the main() function.
system("pause>0");
@@snowandl4195 OK, so it sounds like you solved the issue on your own? Or is it still an issue? The code for this example is here, it should work: github.com/portfoliocourses/cplusplus-example-code/blob/main/destructor_basics.cpp
@@PortfolioCourses Yes, I solved the problem, and this code is system("pause>0");
It is the cause of the problem
Awsome tutorials. Thanks for your effort!
Awesome video. Thank you so much 🙏
You’re welcome Ayoub, I’m glad you enjoyed it! :-)
ones I run clear the g++ to compile it and now at the 3rd compilation I get this? [error: cannot convert ‘double*’ to ‘double’ in assignment
12 | number = (double *) malloc(sizeof(double));] - did you see any issues here in my line? Thank you first run all go but during the Video I enter 3lines more and then... :-(
Thank you for this Video I'm a beginner in C++
I found the failure!
private:
double *number; //here I loose the * and then this Error occur
Hey, all great tutorial videos out there, thx! I want to ask that some videos are covered in C but not in C++, might due to the reason C++ tutorial is not done, so could I use those "missing" videos in C to cover the same concept in C++?like pointer, dynamic allocation, etc. Cause Im taking C++ course rn.
For the most part.... yes. C++ basically maintains compatibility with C for the most part. So if a program works in C, it will work in C++. But this is only "mostly" true, there are some small differences and exceptions here and there too. e.g. in C we can have:
int *data = malloc(sizeof(int) * 50);
but in C++ we need to have:
int *data = (int) malloc(sizeof(int) * 50);
Also, is that the horse from Horsin' Around?
hahh I hear the voice. love the interaction. thank u@@PortfolioCourses
simple and to the point explanation thank you
You’re welcome! :-)
I love your lessons!
Сan you make a video on how to create a binary like "BMP" with file header.
Thank you. I will add this to the list of video requests. :-)
Is is good to use delete operator inside the destructor?
Sometimes we really should in order to “clean up” things that the object is responsible for cleaning up. Like if you delete a Person object and a Hand object is created and “owned” by that Person object from initialization until deletion then the Person object should delete it, for example.
@@PortfolioCoursesOkay, Got it! Btw Your content is just mind blowing!🔥Keep sharing knowledge with begginers like us!
Sir your tutorials are so helpful. Thank you a lot.
You're very welcome Tomi, I'm glad you find them helpful! :-)
Great content ! Keep on the great work !
Thank you! :-D
Using malloc and free inside of a C++ class in 2022 is a very edgy style choice. "That's a bold strategy cotton!"
For a basic double array it won't matter, but I suppose new learners watching this video might not know that or what malloc is either... maybe one day I'll make another destructor video using new instead.
@@PortfolioCourses Its not too hard to understand what it is doing, I just found it a wild contrast of the old C style and modern C++ tools.
Though if going modern in a new video you should probably should just skip right to a unique_ptr or make_unique;
new and delete have been superseded for over a decade [but yes they are still popular in the wild]
Smart pointers are pretty neat and something I want to cover as well. I’m not a big fan of how many ways it’s possible to do things in C++, I’ve come to prefer more opinionated languages and technologies like Python over the years.
@@PortfolioCourses The wide number of options is just a natural outcome of maintaining decades of backward compatibility. However most of those other options are essentially deprecated and only exist for that backward compatibility and occasionally some niche boilerplate use cases. That is, combining "C with Classes" features with C++20 features is technically possible but not the intended use; it would be like mixing Python 1, 2, 3, and cython into a mutant program. (If Python had backward compatibility.)
The example here of dynamic allocation, the Core C++ guidelines that accompany the standard, consider new, and delete as completely outdated, with smart pointers being a zero overhead replacement everywhere except in the writing of the smart pointers. (They are implemented as library class templates, not core built ins.)
Malloc and Free are not part of C++, they are C, isoC++ just happens to adopt most of IsoC for compatibility. (There are a couple C keywords that are not in a C++ compiler, and a few that emulate C but are different down deep.) So while C++ is permissive for those that need it to be, it is also quite opinionated.
@@mytech6779 I prefer opinionated technologies that are not permissive. I've never heard the term opinionated applied to a technology that is also permissive, that's interesting that a technology could be both at the same time. My issue with things being "essentially" deprecated is that we know people will use them anyways, whether they should or shouldn't.
Hey professor, it's look like many different ways made Destructor called. So when exactly is Destructor called? Or how many ways to make Destructor called?
When an object goes out of the scope, when the program end, or when delete operator is called?
I'm so confused right now.
It's definitely confusing, but yes, you're correct, those are the 3 main ways that a destructor is called: when the program terminates, when the scope containing the object ends, and when the delete operator is called. There are some other ways that a destructor can be called, for example if we are using inheritance in our program, that is covered in those videos. 🙂
@@PortfolioCourses thank you i got it😊
@@korngsamnang You're welcome! 😀
@@PortfolioCourses Hi just reading the commnets- just another question - i understand that there are 3 main ways, how do you choose when do call the delete operator? Also, from what I understand, there is an implicit destructor in the class even if we don't write it, so if thats the case, when do we write one and when do we not?
I feel so hard to understand pointer concept.i didn't clearly about that since i've learned c/c++.
I think pointers are one of the hardest things to learn in C/C++ Korng! Maybe this video will help you out: ua-cam.com/video/2GDiXG5RfNE/v-deo.html. 🙂
I would say the main issue with pointers the fact they didn't work with them, for example i used to use cheat engine and that really helped me grasp pointers and assembly@@PortfolioCourses
great video once again
Thank you again Victor! :-D
great vid
Thank you! :-)
Nice
Thank you! :-)
@@PortfolioCourses no problem man,i learn a lot from u
So a destructor is kind of like a garbage collector under the hood? I likey..
I wish there were Turkish subtitles :(