Destructor Basics | C++ Tutorial

  Рет қаралды 19,702

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 49
@menachemlevi
@menachemlevi 9 ай бұрын
you are a king of explanation
@Architector120
@Architector120 2 жыл бұрын
I love your lessons! Сan you make a video on how to create a binary like "BMP" with file header.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you. I will add this to the list of video requests. :-)
@thee3a
@thee3a 2 жыл бұрын
Super clear explanations. Thank you!!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome Thea! 😀
@EsraUn-hf9zt
@EsraUn-hf9zt 3 ай бұрын
I wish there were Turkish subtitles :(
@korngsamnang
@korngsamnang 2 жыл бұрын
I feel so hard to understand pointer concept.i didn't clearly about that since i've learned c/c++.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I think pointers are one of the hardest things to learn in C/C++ Korng! Maybe this video will help you out: kzbin.info/www/bejne/aHinmot9areZhKc. 🙂
@hodayfa000h
@hodayfa000h 3 ай бұрын
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
@weakbit633
@weakbit633 4 ай бұрын
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
@snowandl4195
@snowandl4195 2 жыл бұрын
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
@snowandl4195 2 жыл бұрын
Sorry to bother you, I was using this code at the bottom of the main() function. system("pause>0");
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@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
@snowandl4195
@snowandl4195 2 жыл бұрын
@@PortfolioCourses Yes, I solved the problem, and this code is system("pause>0"); It is the cause of the problem
@ayoubmounadi2142
@ayoubmounadi2142 Жыл бұрын
Awesome video. Thank you so much 🙏
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome Ayoub, I’m glad you enjoyed it! :-)
@maulikshah9122
@maulikshah9122 3 ай бұрын
Is is good to use delete operator inside the destructor?
@PortfolioCourses
@PortfolioCourses 3 ай бұрын
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.
@maulikshah9122
@maulikshah9122 3 ай бұрын
@@PortfolioCoursesOkay, Got it! Btw Your content is just mind blowing!🔥Keep sharing knowledge with begginers like us!
@ieduardoms
@ieduardoms Жыл бұрын
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.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Eduardo! :-)
@chenchen-eo4yf
@chenchen-eo4yf 8 ай бұрын
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.
@PortfolioCourses
@PortfolioCourses 8 ай бұрын
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);
@PortfolioCourses
@PortfolioCourses 8 ай бұрын
Also, is that the horse from Horsin' Around?
@chenchen-eo4yf
@chenchen-eo4yf 8 ай бұрын
hahh I hear the voice. love the interaction. thank u@@PortfolioCourses
@korngsamnang
@korngsamnang 2 жыл бұрын
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.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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. 🙂
@korngsamnang
@korngsamnang 2 жыл бұрын
@@PortfolioCourses thank you i got it😊
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@korngsamnang You're welcome! 😀
@michellevan5693
@michellevan5693 Жыл бұрын
@@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?
@tomitomi7941
@tomitomi7941 Жыл бұрын
Sir your tutorials are so helpful. Thank you a lot.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome Tomi, I'm glad you find them helpful! :-)
@tekkel06
@tekkel06 2 жыл бұрын
Great content ! Keep on the great work !
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you! :-D
@Vichained
@Vichained 2 жыл бұрын
great video once again
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you again Victor! :-D
@adelmae9037
@adelmae9037 Жыл бұрын
simple and to the point explanation thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome! :-)
@cd-stephen
@cd-stephen Жыл бұрын
great vid
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you! :-)
@jonjones6218
@jonjones6218 2 жыл бұрын
Nice
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you! :-)
@jonjones6218
@jonjones6218 2 жыл бұрын
@@PortfolioCourses no problem man,i learn a lot from u
@mytech6779
@mytech6779 2 жыл бұрын
Using malloc and free inside of a C++ class in 2022 is a very edgy style choice. "That's a bold strategy cotton!"
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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.
@mytech6779
@mytech6779 2 жыл бұрын
@@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]
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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.
@mytech6779
@mytech6779 2 жыл бұрын
​@@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.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@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.
Using ofstream To Write To Files | C++ Tutorial
5:11
Portfolio Courses
Рет қаралды 7 М.
new & delete Operators For Dynamic Memory Allocation | C++ Tutorial
15:52
Portfolio Courses
Рет қаралды 29 М.
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 5 МЛН
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 256 МЛН
Constructor Basics | C++ Tutorial
7:08
Portfolio Courses
Рет қаралды 24 М.
Introduction To Classes And Objects | C++ Tutorial
11:49
Portfolio Courses
Рет қаралды 58 М.
C++ Programming Tutorial 88 - Constructors and Destructors
5:34
Caleb Curry
Рет қаралды 42 М.
Abstract Classes And Pure Virtual Functions | C++ Tutorial
11:05
Portfolio Courses
Рет қаралды 16 М.
Introduction To Inheritance | C++ Tutorial
9:38
Portfolio Courses
Рет қаралды 21 М.
C++ CONSTRUCTORS explained easy 👷
8:55
Bro Code
Рет қаралды 15 М.
C++ Class Destructors [6]
7:33
Professor Hank Stalica
Рет қаралды 2,2 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 811 М.
Public And Private Access Specifiers | C++ Tutorial
8:49
Portfolio Courses
Рет қаралды 40 М.