To to avoid misunderstanding in 5:50: destructor and freeing object's memory are two different and unrelated things. Destructor is used to free member resources, that were explicitly allocated by the object, not to free the object itself. So, if there are no such members, destructor is not needed. Also, destructor doesn't call parent classes destructors or members destructors. They are get called outside of context of object's destructor. So, it have nothing to do with freeing parent's resources or member objects. Also, calling 'delete' on pointer that was not created by 'new' is always bad idea, because 'delete' primary function is to free memory allocated from heap (it have nothing to do with stack allocated objects). Anyway, the video is great!
about your second statement, "Also, destructor doesn't call parent classes destructors or members destructors" seems to be partially incorrect. In C++, when an object is destroyed, the destructor does indeed get involved with the cleanup of its member objects and base classes. Here's how it works: When an object is destroyed, its destructor is called. After the derived class destructor's body is executed, the destructors of its base classes are called, in the reverse order of their appearance in the inheritance list. Additionally, the destructors for its member objects are called after the destructor body is executed and before the base class destructors are called. The member objects are destroyed in reverse order of their declaration.
i don't know you guys are the same as me or not by fully grasping and understanding this video i know 2 things: 1- this guy gives like tons of information and even a single word from him has deep meaning behind it. 2- i know absolutely nothing , i mean nothing literally about c++ and have to re-learn it again.
At 4:16 you declare a method without a return type. The compiler then says '... forbids declaration of 'g' with no type'. It seems like this has nothing to do with copy constructing.
Yes, it's wrong. To test, adding a proper return type to that method will give compiler error "Undefined reference to OpenFile::OpenFile(OpenFile& rhs)"
@Bo Qian Why have not you used OpenFile(const OpenFile&) as semantics of copy constructor. Woud not compiler generate a copy constructor with above semantics. #include using namespace std; class Test { public : Test(string s){cout
I disagree At 4:35, error message is not because g() is not defined but because it has no return type. If you provide return type compilation will be successful but will be failed during linking as no definition is found.
I thought, based on the error message, that the error on line 52 g(OpenFile& f) stems from the fact that g is defined without a return type. Is that not the case?
I have a question. when you moved the destructor onto the heap to successfully use it, it did not print out the body of the constuctor, only the destructor. why is that? Also, all these videos are very well done. Thank you for taken your time in doing this
when we are crating the object on the HEAP using NEW and destroying using DELETE, why is that the private dtor still be called ? what is the role of such a private Dtor, ?
very interesting series and answers many questions , but this video could definitely be summarized in 2-3 minutes instead of 10... No offense, keep up the good work...
"Friends are worse than enemies". wisdom lessons as well :-)
To to avoid misunderstanding in 5:50: destructor and freeing object's memory are two different and unrelated things. Destructor is used to free member resources, that were explicitly allocated by the object, not to free the object itself. So, if there are no such members, destructor is not needed.
Also, destructor doesn't call parent classes destructors or members destructors. They are get called outside of context of object's destructor. So, it have nothing to do with freeing parent's resources or member objects.
Also, calling 'delete' on pointer that was not created by 'new' is always bad idea, because 'delete' primary function is to free memory allocated from heap (it have nothing to do with stack allocated objects). Anyway, the video is great!
about your second statement, "Also, destructor doesn't call parent classes destructors or members destructors" seems to be partially incorrect. In C++, when an object is destroyed, the destructor does indeed get involved with the cleanup of its member objects and base classes. Here's how it works:
When an object is destroyed, its destructor is called.
After the derived class destructor's body is executed, the destructors of its base classes are called, in the reverse order of their appearance in the inheritance list.
Additionally, the destructors for its member objects are called after the destructor body is executed and before the base class destructors are called. The member objects are destroyed in reverse order of their declaration.
i don't know you guys are the same as me or not by fully grasping and understanding this video i know 2 things:
1- this guy gives like tons of information and even a single word from him has deep meaning behind it.
2- i know absolutely nothing , i mean nothing literally about c++ and have to re-learn it again.
Great video. You probably meant 'heap' instead of 'stack' at around 8:32.
I guess he meant 'f' itself which is a pointer to OpenFile is stored on stack, which is correct.
Yes, that was a typo. Nice catch. But even if you give g() a return type, the code will still error out, because copy constructor has no definition.
Thank you for these wonderful videos. Please keep making more :)
Very well explained all concept. Every video is very conceptual.
Thanks man for your wonderful work, it helped alot
Youu are a legend! and your series are amazing! so much useful information! :D
At 4:16 you declare a method without a return type. The compiler then says '... forbids declaration of 'g' with no type'. It seems like this has nothing to do with copy constructing.
Yes, it's wrong. To test, adding a proper return type to that method will give compiler error "Undefined reference to OpenFile::OpenFile(OpenFile& rhs)"
It's a linker error.
@Bo Qian Why have not you used
OpenFile(const OpenFile&) as semantics of copy constructor.
Woud not compiler generate a copy constructor with above semantics.
#include
using namespace std;
class Test
{
public :
Test(string s){cout
'delete this;' should be replaced with '~OpenFile();' (yes - the destructor can be invoked just like any other method)
I tried it, the compiler doesn't let you init. the object to begin with, because there is no accessible destructor.
Nice explanation.
I disagree At 4:35, error message is not because g() is not defined but because it has no return type. If you provide return type compilation will be successful but will be failed during linking as no definition is found.
MinGW g++
Good playlist Bo . Cheers
It actually was printed out, but the console is too small so the printout was scrolled over.
Mr. BoQian, very nice video. May I know which compiler are you using?
This is so very useful Bo. Thank you so much :)
I thought, based on the error message, that the error on line 52 g(OpenFile& f) stems from the fact that g is defined without a return type. Is that not the case?
pls make more such viedos sir..
cheers to you..
thanks
nagesh
Simply GREAT BLESS YOU
I have a question. when you moved the destructor onto the heap to successfully use it, it did not print out the body of the constuctor, only the destructor. why is that? Also, all these videos are very well done. Thank you for taken your time in doing this
when we are crating the object on the HEAP using NEW and destroying using DELETE, why is that the private dtor still be called ?
what is the role of such a private Dtor, ?
These are great videos. Thanks.
great videos :)
summary --> 9:31
Which 'g' method?
How would the 'g' method work without a return type?
Thank you Sir, if passable could you please create videos for Linux IPC
Friends are our enemies. LOL
he is using netneans i suppose! or oracle dev studio
4:34 your explanation of error is wrong. The error there is that method g(openFile& f); has no return type.
what nameis your IDE?
very interesting series and answers many questions ,
but this video could definitely be summarized in 2-3 minutes instead of 10...
No offense, keep up the good work...
TOOOOOOOOOOOoo much ADVANce