473,776 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Containment classes

hi

This is particular to Containment classes .. ( just taking an
example from rougewave )

Can someone point out How destrutor of new RWDate(2, "Nov", 1980)
will be called?
Is is our responsibilty to call it or such container after deleting
the list element calls the destuctor also .
Will appreciate any pointer in this regard ..

RWTPtrHashDicti onary<RWCString , RWDate>
birthdays.inser tKeyAndValue (new RWCString("Ivan "), new RWDate(2,
"Nov", 1980) );

Thanks
CAdiga
#include <rw/tphdict.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>

main() {
RWTPtrHashDicti onary<RWCString , RWDate>
birthdays(RWCSt ring::hash);
birthdays.inser tKeyAndValue
(new RWCString("John "),
new RWDate(12, "April", 1975)
);
birthdays.inser tKeyAndValue
(new RWCString("Ivan "),
new RWDate(2, "Nov", 1980)
);

// Alternative syntax:
birthdays[new RWCString("Susa n")] =
new RWDate(30, "June", 1955);
birthdays[new RWCString("Gene ")] =
new RWDate(5, "Jan", 1981);

// Print a birthday:
RWCString key("John");
cout << *birthdays[&key] << endl;

birthdays.clear AndDestroy();
return 0;
}

Jul 19 '05 #1
2 4515
"Chandrashe kara Adiga" <ca****@cisco.c om> wrote...
This is particular to Containment classes .. ( just taking an
example from rougewave )

Can someone point out How destrutor of new RWDate(2, "Nov", 1980)
will be called?
It is impossible to tell without seeing what ".clearAndDestr oy()"
call does to the object ('birthdays').
Is is our responsibilty to call it or such container after deleting
the list element calls the destuctor also .
If I understand what you're asking, then it is _possible_ that
"RWTPtrHashDict ionary" template is implemented so that it calls
'delete' on all of its pointers. However, since it's not a standard
type, how can we tell? If you have the documentation, read it.


Will appreciate any pointer in this regard ..
Here is a hint: in most cases if it is your code that calls 'new'
to create something, it's _your_ code that should call 'delete'
to destroy that something.

RWTPtrHashDicti onary<RWCString , RWDate>
birthdays.inser tKeyAndValue (new RWCString("Ivan "), new RWDate(2,
"Nov", 1980) );

Thanks
CAdiga
#include <rw/tphdict.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>

main() {
RWTPtrHashDicti onary<RWCString , RWDate>
birthdays(RWCSt ring::hash);
birthdays.inser tKeyAndValue
(new RWCString("John "),
new RWDate(12, "April", 1975)
);
birthdays.inser tKeyAndValue
(new RWCString("Ivan "),
new RWDate(2, "Nov", 1980)
);

// Alternative syntax:
birthdays[new RWCString("Susa n")] =
new RWDate(30, "June", 1955);
birthdays[new RWCString("Gene ")] =
new RWDate(5, "Jan", 1981);

// Print a birthday:
RWCString key("John");
cout << *birthdays[&key] << endl;

birthdays.clear AndDestroy();
return 0;
}


Victor
Jul 19 '05 #2
Chandrashekara Adiga wrote:
hi

This is particular to Containment classes .. ( just taking an
example from rougewave )

Can someone point out How destrutor of new RWDate(2, "Nov", 1980)
will be called?
It will be called when you delete the object.
Is is our responsibilty to call it or such container after
deleting the list element calls the destuctor also .
I'm not quite sure I understand the above sentence, but if you destroy a
pointer, the object it points to doesn't get destroyed, so if you
dynamically allocated it, you must delete it, too.
RWTPtrHashDicti onary<RWCString , RWDate>
birthdays.inser tKeyAndValue (new RWCString("Ivan "), new RWDate(2,
"Nov", 1980) );


Do you really need all those pointers and that dynamic allocation? Looks
unneccesary to me. If you don't use dynamic allocation with new, you
don't need to care about deleting the object.

Jul 19 '05 #3

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

Similar topics

1
3930
by: Dave | last post by:
Hello all, The methodology of policy-based design states that one should inherit from policy classes and, of course, these classes must provide an agreed-upon public interface and semantics. I would like to understand better why inheritance, rather than containment, is espoused. The only things I can see that inheritance provides beyond containment is the possibility of polymorphism and access to protected members. Since neither of...
1
3250
by: Baski | last post by:
Does anyone knows any article explains effective use of containment and aggregation with interfaces using C#. Thanks Baski
2
9505
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how to do that? Thanks. Tsung-Yu
18
2048
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise. Yet, in my understanding, attributes are only __gc and __value class specific and do not apply to __nogc classes. Is this correct ? If so, how is the packing alignment of __nogc classes stored ?
3
1350
by: Mr Dyl | last post by:
Hello, maybe somebody can enlighten me? :) I wasn't really sure how to concisely describe the following scenario so it was tricky to search for help. Simplifying the problem... I have a home which contains people. I also want a SpecialHome which has to contain a set of SpecialPersons.
0
1891
by: David Veeneman | last post by:
This post is for the Google crawler-- no response in required. Can a containment hierarchy made up of two collections derived from BindingList<T> be data-bound to master-detail dataGridView controls? Assume a collection, CustomerList, derived from BindingList<T>, with a property Orders, of type OrderList, also derived from BindingList<T>. Here is how to create a master-detail pair of grids: In design mode, create a form with two...
2
2283
by: pauldepstein | last post by:
Does anyone know ( giving a URL is obviously o.k.) which of the C++ classes contain each other? (For example, <fstreamcontains <iostream). This did sound to me a bit like a FAQ question so I googled around a bit, but couldn't find it. Apologies if it's a FAQ. Paul Epstein
3
2904
by: Smithers | last post by:
I'm designing a Windows Forms application for a medical clinic that keeps complete and comprehensive histories on its patients: histories of medical conditions and facts, financial facts, psychosocial evaluations, etc. There is a whole bunch of stuff they track about each patient. I am tentatively planning on implementing something close to the MVP pattern, with this "Person" class at the BOL. The "Person" class would be akin to the MVP...
12
5471
by: Daz | last post by:
Hi guys, I'm trying to make a script.aculo.us sortable list have a limited number of elements in it. Now I can check for this really easily and have a warning message, and of course the php throws an error back anyway so they can't actually save more than the limit, but, is there a way I can stop them from dropping the damn thing in the list if it's full? I thought about dynamically setting the containment array, so that
0
9627
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10287
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10060
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9922
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7469
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5367
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5492
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3621
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2859
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.