473,789 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base classes destructors

Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

Thanks in advance

Nuno Barros
Jul 19 '05 #1
3 2717

Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

The base destructor will be called implicitly after the derived constructor
completes; you don't have to call it.
Jul 19 '05 #2

"Nuno Barros" <nu*********@fc .ul.pt> wrote in message news:a8******** *************** ***@posting.goo gle.com...
Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?


Destructors for the base classes and member objects are called automatically
(after the destructor body of the derived class is run).
Jul 19 '05 #3
Buster Copley wrote:
Nuno Barros wrote:
Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

Thanks in advance

Nuno Barros

Provided the destructor is declared virtual in the base class, the less-
derived classes' destructors will be invoked when the more-derived
classes' destructors are completed.


I should have paused for thought, I've got it all backwards. Virtual
destructors are for deleting derived-class objects through base-class
pointers. The other posts are correct. Sorry!
Good luck,
Buster.


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
5844
by: Marcin Vorbrodt | last post by:
Taken out of C++ In a Nutshell book... Example 7-18: Using an abstract classes as interface specification. struct Runnable { virtual void run() = 0; }; struct Hashable { virtual size_t hash() = 0; };
2
4554
by: Chunhui Han | last post by:
Hi, I was recently reading about virtual base classes in C++. The book I was reading says that it is illegal to have non-virtual destructor for the virtual base class. It seems to me that virtual destructors are essential when the class has virtual functions, since this class is supposed to be used as a base class for polymorphism. But what is the real reason for a virtual destructor in a virtual base class? Thanks,
23
5184
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
7
1890
by: qazmlp | last post by:
When a member function is declared as virtual in the base class, the derived class versions of it are always treated as virtual. I am just wondering, why the same concept was not used for the destructors. What I am expecting is, if the destructor is declared as virtual in base, the destructors of all its derived classes also should be virtual always. What exactly is the reason for not having it so?
2
1816
by: Dave | last post by:
Hi, Does the destructor of a derived class will invoke base class destructor implicitly? D
27
2135
by: tuvok | last post by:
Is it correct that the virtual dtor of base gets called implicitly? Here's some code to demonstrate what I mean: Class B has a virtual destructor, so has class D which is derived from B. Deleting D calls the dtor of D and then the dtor of B. I was thinking that this would be true only for non-virtual dtor case, but I wouldn't have expected it happen for a virtual dtor. For a class with a virtual dtor I would have expected that only the...
8
1767
by: LAvoisieR | last post by:
Following test code behaviour suprised me and I dont know what's wrong with this. I have two overloaded constructors within base class and virtual destructor implemented. Derived class uses protected non-parametrized constructor of base class which DOES NOT initialize private member 'value'. But by calling both destructors virtually, binary does not complaint about deleting uninitialized pointer. WHY ?? C++ compiler used: G++ 3.4.3 ...
22
2414
by: ypjofficial | last post by:
Hello All, I have following doubt.. class abstractclass { public: abstractclass(){} virtual void method()=0; };
1
2529
by: Rune Allnor | last post by:
Hi all. I am sure this is an oldie, but I can't find a useful suggestion on how to solve it. I have a class hierarchy of classes derived from a base class. I would like to set up a vector of smart pointers to the base class, and access the virtual functions of any class in the hierarchy through the virtual functions.
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.