Novice consulting a problem, a base class pointer, anti-fuzzy instance class object, if the destructor, must write virtual function, end of the program will not perform to subclass destructor, can lead to memory leaks
, if the base class didn't write the destructor, spicy yao by default will be the base class destructor is virtual function? See a lot of DEMO online, is implements the polymorphic calls, no see have to deal with the base class destructor, so there is the question, many thanks!
CodePudding user response:
Try not to know?
CodePudding user response:
The virtual base class destructor is "best practice" - should always use them to avoid memory leaks, hard to detect,
CodePudding user response:
reference 1/f, the truth is more important than right or wrong response: try don't you know? if this is the default under the condition of not write a destructor, and can't write the destructor print it out, how to try? Consult, CodePudding user response:
refer to the second floor met the goddess response: virtual base class destructor is "best practice" - you should always use them to avoid memory leaks, hard to detect, Yeah, I mean if not manually specify is virtual destructor, the default is not? Online mostly about polymorphism of this example, there is no to manually ShenMingJi class destructor is a virtual function, therefore, have any questions, CodePudding user response:
reference csdnbuku reply: 3/f Quote: reference 1/f, the truth is more important than right or wrong response: Try not to know? if this is the default under the condition of not write a destructor, and can't write the destructor print it out, how to try? Consult, You in subclass destructor print once, see the parent class without writing a destructor, a subclass destructor will be invoked, don't you know? CodePudding user response:
reference 4 floor csdnbuku response: Quote: refer to the second floor met the goddess response: The virtual base class destructor is "best practice" - should always use them to avoid memory leaks, hard to detect, Yeah, I mean if not manually specify is virtual destructor, the default is not? Online mostly about polymorphism of this example, there is no to manually ShenMingJi class destructor is a virtual function, has the question reason, Important things to repeat three times: The virtual base class destructor is "best practice" The virtual base class destructor is "best practice" The virtual base class destructor is "best practice" CodePudding user response:
refer to fifth floor truth is right or wrong response: Quote: refer to the third floor csdnbuku response: Quote: reference 1/f, the truth is more important than right or wrong response: Try not to know? if this is the default under the condition of not write a destructor, and can't write the destructor print it out, how to try? Consult, You in subclass destructor print once, see the parent class without writing a destructor, a subclass destructor will be invoked, don't you know? Yes, this kind of situation before tried, not to perform, I afraid I manually wrote a subclass destructor will affect results, mainly because of a lot of online tutorials blog about this polymorphism, are not going to write a destructor, so it was very strange, CodePudding user response:
Online tutorials, blog, such as when a reference is ok, don't see them as the standard. Want to know in detail, combined with the compiler, and c + + standard CodePudding user response:
refer to the eighth floor truth is right or wrong response: online tutorials, blog, such as when a reference is ok, don't see them as the standard. Want to know in detail, combined with the compiler, and c + + standard Makes sense, some tutorials, write some DEMO, new nor delete after processing, the whole tutorial written writing sample replication