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.
--