473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ctor/Dtor order

Hi!

Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.
Jul 19 '05 #1
3 5065


shura wrote:

Hi!

Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


yes. Thats how it is defined to be.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2
"shura" <re***************@paragon.ru> wrote...
Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


I don't think it's good to _assume_, but the order
you describe is required by the Standard. So, all
Standard-compliant compilers should do it that way.

Victor
Jul 19 '05 #3
In article <bg**********@newsreader.mailgate.org>,
shura <re***************@paragon.ru> wrote:
Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


Yes. Of course, B may have its own subobjects and so on.
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 19 '05 #4

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

Similar topics

2
by: Eric Liu | last post by:
Hi, Can anyone explain why the following code works? The static object creation is via the private ctor. If I try to define a X object in the mainline, of course I will get complaint about...
6
by: Robert Sturzenegger | last post by:
class C { public: C() { cout << "ctor" << endl; } C(const C & rhs) { cout << "copy ctor" << endl; } ~C() { cout << "dtor" << endl; } }; C c0; // A C c1 = C(); // B
10
by: richardclay09 | last post by:
The output of this: #include <iostream> #include <vector> using namespace std; struct X { int i; X(const X& x) : i(x.i) { cout << "ctor copy: " << i << endl;
1
by: pmastroianni | last post by:
When a class is instantiated, will the ctor and dtor occupy memory? IF ctor and dtor do occupy memory of an instantiated class where would they be in memeory?
7
by: Thomas | last post by:
I have a class foo whose ctor might throw an exception. When I create a foo object using "foo* myfoo = new foo;", and the ctor throws an exception, do I need to delete myfoo to free its memory?
6
by: puzzlecracker | last post by:
When ctor throws an exception, dtor is not called for that object (correct me if I am wrong) - then how would already allocated memebers de-allocated? Thanks.
9
by: utab | last post by:
Dear all, How do experienced programmers using this group use the rule of thumb,namely copy ctor, assignment operator, and dtor. example if the class does not need them dont use and define...
8
by: Grizlyk | last post by:
Good morning. Look here: http://groups.google.com/group/fido7.ru.cpp.chainik/browse_frm/thread/7341aba5238c0f79 and here:...
5
by: peifeng_w | last post by:
Hi, try the following code with flag=0/1/2. #include<iostream> using namespace std; #define flag 2//option:0,1,2 class C {
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.