473,394 Members | 1,946 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,394 software developers and data experts.

How to call Aggregator class destructor?

Hi All,

I have a Aggregator class that aggregates two classes. When
any of the two aggregated
classes die I want the Aggregator to die as well.

How do I call the Aggregator class's destructor from any of the
Aggregated class's destructor?

Thanks in advance.

Hari

Nov 3 '06 #1
1 2043
haries wrote:
Hi All,

I have a Aggregator class that aggregates two classes. When
any of the two aggregated
classes die I want the Aggregator to die as well.
No, you don't want that. The language is designed the other way around: if
an object dies, then so do all its subobjects. That you have a need for
doing it in reverse indicates that your design is seriously off base.

What you really want to do is to redesign your classes so that they go with
the flow of the language and not against it.

Please post some code to illustrate the underlying problem you are trying to
solve. Maybe, you just painted yourself into a corner.

How do I call the Aggregator class's destructor from any of the
Aggregated class's destructor?
Suppose you have an aggregate:

class Agg {
A sub_obj_a;
B sub_obj_b;
...
};

And suppose you also have:

~A::A() {
some black magic calling ~Agg() for the right instance;
}

Then you are in deep waters because ~Agg() calls sub_obj_a.~A() which then
again calls ~Agg(), and so on and so forth. The standard does not even
guarantee this, because it deems calling the destructor of an object twice
undefined behavior already.
Best

Kai-Uwe Bux
Nov 4 '06 #2

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

Similar topics

23
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) .
8
by: Arne Claus | last post by:
Hi I've got a little question about the following construct: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class a { public: a()...
9
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
2
by: rogero | last post by:
I'm having a nasty problem where the destructor of an automatic variable is invoked with the wrong address during stack unwinding. Below is a small example program. Roger Orr -- MVP in C++ at...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
7
by: michael | last post by:
Hi All, I have written the following to illustrate a problem. I know I have some magic numbers etc please ignore them. What I do not follow is why the line marked results in a call to the...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
3
by: Rudi | last post by:
Hello, following problem: At program end or release an assembly a serial device should get a final exit sequence. How can I do this? With Dispose() it's no problem, but this assembly is used...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.