473,408 Members | 2,405 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,408 software developers and data experts.

lists of objects..... and destructors....

If you have a list of object like:

class image : public std::list<element>
Then does the element class need the copy constructor, operator=() and
the destructor methods implemented?

Seems to me that when the image is detroyed that the list is not
cleared...
Maybe this is why people are telling me I shouldn't inherit from
std::list....

Apr 4 '07 #1
3 1200
On Apr 4, 1:33 pm, "SpreadTooThin" <bjobrie...@gmail.comwrote:
If you have a list of object like:

class image : public std::list<element>

Then does the element class need the copy constructor, operator=() and
the destructor methods implemented?

Seems to me that when the image is detroyed that the list is not
cleared...
Maybe this is why people are telling me I shouldn't inherit from
std::list....
Also when the list is cleared then the destructor of each object in
the list is supposed to be called as well right?

Apr 4 '07 #2
SpreadTooThin wrote:
On Apr 4, 1:33 pm, "SpreadTooThin" <bjobrie...@gmail.comwrote:
>If you have a list of object like:

class image : public std::list<element>
If you're implementing in term of 'list', don't inherit publicly,
inherit privately and re-implement the functionality you need.
>Then does the element class need the copy constructor, operator=()
and the destructor methods implemented?
Depends. Does the list ever get sorted? Does it ever get any
insertions in it?
>Seems to me that when the image is detroyed that the list is not
cleared...
I would strongly doubt that. Any proof (code)?
>Maybe this is why people are telling me I shouldn't inherit from
std::list....

Also when the list is cleared then the destructor of each object in
the list is supposed to be called as well right?
Yes.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 4 '07 #3
On Apr 4, 9:33 pm, "SpreadTooThin" <bjobrie...@gmail.comwrote:
If you have a list of object like:
class image : public std::list<element>
Then does the element class need the copy constructor, operator=() and
the destructor methods implemented?
I'm not sure what you mean by "implemented" here. In order to
instantiate a standard container, the contained type must have a
publicly accessible copy constructor, assignment operator and
destructor. (The last is so obvious, I'm not even sure the
standard mentions it explicitly. Without a publicly accessible
destructor, there's not much you can do with the type, except
derive from it.) It the type is a class type, and you don't
declare one of these, the compiler will declare it, and provide
the implementation. If you declare it, you must make it public,
and provide an implementation.
Seems to me that when the image is detroyed that the list is not
cleared...
Why? If the destructor of image is called, it will call the
destructor of its base class, and the destructor of std::list
will destruct any elements in the list at that time.
Maybe this is why people are telling me I shouldn't inherit from
std::list....
It's generally not a good idea to derive from one of the
standard containers, but this has nothing to do with it.

--
Apr 5 '07 #4

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

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
3
by: joe martin | last post by:
Does anyone know when or if destructors for statically declared objects are called? I am just wondering if I am leaking system resources each time i exit my program. Thanks, -Joe ...
3
by: Andrew.Morgan | last post by:
Hi I have three classes TDigest, THash and TSHA1. //--------------------------------------------------------------------------- class TDigest { public: // Constructors. TDigest(int Count);
5
by: canned.net | last post by:
I have a class Scene that has several subclasses: World, Vault, etc. I fill a vector with these classes and then cannot go through and delete them. What's the trick to deleting pointers from a...
10
by: amparikh | last post by:
Ok, my question is not about Virtual destructors and why, but more on the significance. Generally we have a virtual destructor in the base class ( and inadvertently in the derived class) so that...
7
by: Sammy | last post by:
Its slow but Im in the process of converting some of my admittedly ugly code into STL. At the moment Im working to change a mess that I like to call a linked list when Im in a generous mood....
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
4
by: Robbie Hatley | last post by:
I've been playing with "auto_ptr" and the "Resource Acquisition Is Initialization" concept. On page 199 of Lippman's book "Effective C++" he says "All active local class objects of a function are...
8
by: jayaramganapathy | last post by:
Hello friends, I have a map like std::map< std::string , std::map<std::string, std::string>* EpPropCache::propertyCache ; (This is a static instance and taken from *.cpp file) As you can see...
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.