473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Is a created before b?

ikl
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};

Is a for sure instantiated before b? If not, then is there any way to make
sure that? How to make sure a is deleted after b's deletion?

Thanks!


Jul 22 '05 #1
16 1773
ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};

Is a for sure instantiated before b?


Yes. Member variables are constructed in the order in which they appear
in the class definition.

--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 22 '05 #2
ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};

Is a for sure instantiated before b?


Yes. Member variables are constructed in the order in which they appear
in the class definition.

--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 22 '05 #3
ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};

Is a for sure instantiated before b?
Yes.
How to make sure a is deleted after b's deletion?


Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted." The answer is that "b" will be destructed
first unless you jump through some pretty contorted hoops. Is there a
particular situation in which you find the default behavior unsuitable?
Jul 22 '05 #4
ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};

Is a for sure instantiated before b?
Yes.
How to make sure a is deleted after b's deletion?


Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted." The answer is that "b" will be destructed
first unless you jump through some pretty contorted hoops. Is there a
particular situation in which you find the default behavior unsuitable?
Jul 22 '05 #5

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};
int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make
sure that? How to make sure a is deleted after b's deletion?

Thanks!


Jul 22 '05 #6

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};
int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make
sure that? How to make sure a is deleted after b's deletion?

Thanks!


Jul 22 '05 #7
Jeff Schwab wrote:
How to make sure a is deleted after b's deletion?
Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."


I think the word is "destroyed" ;-)
The answer is that "b" will be destructed first unless you jump
through some pretty contorted hoops. Is there a particular situation
in which you find the default behavior unsuitable?


The OP actually wanted that behaviour.

Jul 22 '05 #8
Jeff Schwab wrote:
How to make sure a is deleted after b's deletion?
Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."


I think the word is "destroyed" ;-)
The answer is that "b" will be destructed first unless you jump
through some pretty contorted hoops. Is there a particular situation
in which you find the default behavior unsuitable?


The OP actually wanted that behaviour.

Jul 22 '05 #9
Rolf Magnus wrote:
Jeff Schwab wrote:

How to make sure a is deleted after b's deletion?


Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."

I think the word is "destroyed" ;-)


I think both terms are fine. "Destruct" is what an object does when its
"destructor" is called, the process being known as "destruction."

"destroy" happens to be the name of the method in the standard
allocators that causes the destruction of an object, so I prefer to say
an object whose destructor is invoked implicity by the run-time
environment is "destructed," rather than "destroyed."
The answer is that "b" will be destructed first unless you jump
through some pretty contorted hoops. Is there a particular situation
in which you find the default behavior unsuitable?

The OP actually wanted that behaviour.


Yes, I see (upon re-reading the OP) that you're right. What I said is
true, it's just not very useful. :)
Jul 22 '05 #10
Rolf Magnus wrote:
Jeff Schwab wrote:

How to make sure a is deleted after b's deletion?


Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."

I think the word is "destroyed" ;-)


I think both terms are fine. "Destruct" is what an object does when its
"destructor" is called, the process being known as "destruction."

"destroy" happens to be the name of the method in the standard
allocators that causes the destruction of an object, so I prefer to say
an object whose destructor is invoked implicity by the run-time
environment is "destructed," rather than "destroyed."
The answer is that "b" will be destructed first unless you jump
through some pretty contorted hoops. Is there a particular situation
in which you find the default behavior unsuitable?

The OP actually wanted that behaviour.


Yes, I see (upon re-reading the OP) that you're right. What I said is
true, it's just not very useful. :)
Jul 22 '05 #11
ikl
Neil Zanella <nz******@cs.mun.ca> wrote in message
news:Pi**************************************@garf ield.cs.mun.ca...

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};


int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make sure that? How to make sure a is deleted after b's deletion?

Thanks!

Thanks to you all! This is not a question to me any more.

Is there any difference if a and b in any order on initializer lists for
class C?

Does an initializer list always go with a definition of a constructor not
declaration?

If there is a method in C that makes the class C like,
class C
{
A a;
B b;
public:
void method1(A& a1, B& b1);
};

When method1() is invoked, is it always safe to say that a and b have been
created already?
Jul 22 '05 #12
ikl
Neil Zanella <nz******@cs.mun.ca> wrote in message
news:Pi**************************************@garf ield.cs.mun.ca...

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};


int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make sure that? How to make sure a is deleted after b's deletion?

Thanks!

Thanks to you all! This is not a question to me any more.

Is there any difference if a and b in any order on initializer lists for
class C?

Does an initializer list always go with a definition of a constructor not
declaration?

If there is a method in C that makes the class C like,
class C
{
A a;
B b;
public:
void method1(A& a1, B& b1);
};

When method1() is invoked, is it always safe to say that a and b have been
created already?
Jul 22 '05 #13

"ikl" <ik***@dsp.com> wrote in message
news:RH********************@bgtnsc05-news.ops.worldnet.att.net...
Neil Zanella <nz******@cs.mun.ca> wrote in message
news:Pi**************************************@garf ield.cs.mun.ca...

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};
int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make sure that? How to make sure a is deleted after b's deletion?

Thanks!

Thanks to you all! This is not a question to me any more.

Is there any difference if a and b in any order on initializer lists for
class C?


The order of initialization is that of the
order of the member definitions. The expressions
in the initializer list can be in any order, and
do not affect initialization order.

Does an initializer list always go with a definition of a constructor not
declaration?
Correct.

If there is a method in C that makes the class C like,
class C
{
A a;
B b;
public:
void method1(A& a1, B& b1);
};

When method1() is invoked, is it always safe to say that a and b have been
created already?


Yes. Once a constructor has run (whether it's user-defined
or not), the object exists, and member functions can be
invoked against it.

-Mike
Jul 22 '05 #14

"ikl" <ik***@dsp.com> wrote in message
news:RH********************@bgtnsc05-news.ops.worldnet.att.net...
Neil Zanella <nz******@cs.mun.ca> wrote in message
news:Pi**************************************@garf ield.cs.mun.ca...

Since the clas A instance is specified prior to the class B instance it
will be guaranteed to be constructed before the class B instance. The
destructors are then guaranteed to be run in the reverse order. This
is regardless of any way constructors for such classes A and B may
be specified in initializer lists for class C.

Regards,

Neil

On Mon, 5 Apr 2004, ikl wrote:
Given three classes:

class A
{
};

class B
{
};

class C
{
A a;
B b;
};
int main() {
C c;
}

Is a for sure instantiated before b? If not, then is there any way to make sure that? How to make sure a is deleted after b's deletion?

Thanks!

Thanks to you all! This is not a question to me any more.

Is there any difference if a and b in any order on initializer lists for
class C?


The order of initialization is that of the
order of the member definitions. The expressions
in the initializer list can be in any order, and
do not affect initialization order.

Does an initializer list always go with a definition of a constructor not
declaration?
Correct.

If there is a method in C that makes the class C like,
class C
{
A a;
B b;
public:
void method1(A& a1, B& b1);
};

When method1() is invoked, is it always safe to say that a and b have been
created already?


Yes. Once a constructor has run (whether it's user-defined
or not), the object exists, and member functions can be
invoked against it.

-Mike
Jul 22 '05 #15
Jeff Schwab wrote:
Rolf Magnus wrote:
Jeff Schwab wrote:

How to make sure a is deleted after b's deletion?
Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."


I think the word is "destroyed" ;-)

I think both terms are fine. "Destruct" is what an object does when its
"destructor" is called, the process being known as "destruction."


I don't think Rolf was correcting your terms, just your
grammar/spelling: "destructed" is not in the English dictionary.

Destruct - to Destroy. "It has been destroyed - I see only destruction."

--
Ben Measures
Software programming, Internet design/programming, Gaming freak.

http://ben.measures.org.uk - when I find time
Jul 22 '05 #16
Jeff Schwab wrote:
Rolf Magnus wrote:
Jeff Schwab wrote:

How to make sure a is deleted after b's deletion?
Since neither "a" nor "b" is allocated dynamically, I think you mean
"destructed," not "deleted."


I think the word is "destroyed" ;-)

I think both terms are fine. "Destruct" is what an object does when its
"destructor" is called, the process being known as "destruction."


I don't think Rolf was correcting your terms, just your
grammar/spelling: "destructed" is not in the English dictionary.

Destruct - to Destroy. "It has been destroyed - I see only destruction."

--
Ben Measures
Software programming, Internet design/programming, Gaming freak.

http://ben.measures.org.uk - when I find time
Jul 22 '05 #17

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

Similar topics

21
by: André | last post by:
Short version of what I am looking for: Given a class "public_class" which is instantiated a few times e.g. a = public_class() b = public_class() c = public_class() I would like to find...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
1
by: Lalit | last post by:
Hi, My application has two methods which creates buttons at runtime. In one method I am able to handle the events of the buttons created at run time, but in other I am not. The code structure...
7
by: MariusI | last post by:
Are objects implicitly stored in the TLS of the currently running thread? When creating multithreaded applications i get errors when accessing data from a different thread than the thread used to...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
3
by: Happy Man | last post by:
Why we created All praise is due to Allah and may His peace and blessings be upon his last messenger (saaw) and on all those who follow the path of righteousness until the last day. We have...
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
0
by: dhvenkat | last post by:
Hi all, Im facing issues in generating the second mail-merge document when the first document created is still open. Its a web based application, and we submit the details for mail-merge after...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.