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! 16 1772
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.
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.
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?
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?
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!
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!
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.
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.
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. :)
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. :)
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?
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?
"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
"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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |