473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constructor call during inheritance

Hi all,
Suppose class A is inherited from class B and Class B is inherited
from class C. Could anyone explain on how the C++ compiler construct
the A object and how is A object destroyed by compiler when it is out
of scope. Can anyone explain what does the compiler do in these
process?

thanks in advance

-karups

Oct 6 '07 #1
1 1367
On Oct 6, 2:37 pm, appu <karuppaiah...@ gmail.comwrote:
Suppose class A is inherited from class B and Class B is inherited
from class C. Could anyone explain on how the C++ compiler construct
the A object and how is A object destroyed by compiler when it is out
of scope. Can anyone explain what does the compiler do in these
process?
The rule is that the compiler generates calls to the base class
constructors (using the initialization arguments if there are
any, and the default constructor otherwise) and all member
objects before entering into its own body. Thus, in this case,
the compiler will generate a call to the constructor of B at the
top of the constructor of A. (The same thing happens with B, of
course, so the constructor of B calls the constructor of C.)

Destruction works the same way, except that the calls to the
base class destructors are at the end of the derived class
constructor.

If this isn't described in your basic C++ text, it's time to get
a different text.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 7 '07 #2

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

Similar topics

7
13199
by: Robin Forster | last post by:
I have two classes: aule_gl_window (parent class) and aule_button (sub class) I want to call the super class (parent) constructor code from the sub class constructor.
0
4243
by: Lefevre | last post by:
Hello I recently had troubles with a class inheritance hierarchy. I solved it, but it didn't satisfied me. I found the solution using this forum :) Actualy i found the following message (with no responces associated) :
23
5145
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) .
45
6313
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using parameters, I get CS1501 (no method with X arguments). Here's a simplified example which mimics the circumstances: namespace InheritError { //...
8
1385
by: VK | last post by:
I never managed to ask before: Why this backward way is so often used for constructors: myConstructor = function() { /*empty placeholder*/ } // and then: myConstructor.prototype.methodOne = function() {...} myConstructor.prototype.methodTwo = function() {...} instead of right away:
2
5441
by: Nigel Molesworth | last post by:
I'm doing a Java course. Having gone through the use of accessor (setter and getter) methods for instance variables, it goes on to say: "For reasons that cannot be elaborated upon here, it is safer, where possible, to initialise instance variables directly in a constructor rather than using setter messages." Can anyone offer a simple...
3
3767
by: Marcin Kalicinski | last post by:
Hi, Having the following program: #include <iostream> struct A { A() { std::cout << "A::A()\n"; } A(const A &) { std::cout << "A::A(const A &)\n"; }
4
3882
by: ingoweiss | last post by:
Hi, I am having trouble passing parameters of a Javascript subclass constructor through to it's superclass constructor. I am trying all sorts of things, including the below, but nothing worked so far. Thanks for any help!
3
2233
by: hurcan solter | last post by:
Consider the code fragment; class A { public: A(){} A(int prm):mprm(prm){} int mprm; }; class B:public A {
0
7504
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...
0
7947
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...
1
7461
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...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
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...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
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...

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.