P
Piotr
I am reading Effective STL item 7
My understanding is, instead of doing this:
tempate <typename T>
struct DeleteObject:
public unary_function<const T*, void> {
void operator() (const T* ptr) const
{
delete ptr;
}
}
we should do this:
struct DeleteObject:
tempate <typename T>
void operator() (const T* ptr) const
{
delete ptr;
}
}
because of this "undefined behavior! Deletion of a derived object via a
base class pointer where there is no virtual destructor
void doSomething() {
depque <SpecialString*> dssp;
...
for_each(dssp.begin(), dssp.end(), DeleteObject<string>());
}
My questions are:
1. Why the 'ehanced' implementation DeleteObject: #2, does not need to
inherit unary_function<const T*, void>?
2. Should all my child classes which implement unary_function<const T*,
void> should be converted to 'enhanced implementation (#2)?
Thank you.
My understanding is, instead of doing this:
tempate <typename T>
struct DeleteObject:
public unary_function<const T*, void> {
void operator() (const T* ptr) const
{
delete ptr;
}
}
we should do this:
struct DeleteObject:
tempate <typename T>
void operator() (const T* ptr) const
{
delete ptr;
}
}
because of this "undefined behavior! Deletion of a derived object via a
base class pointer where there is no virtual destructor
void doSomething() {
depque <SpecialString*> dssp;
...
for_each(dssp.begin(), dssp.end(), DeleteObject<string>());
}
My questions are:
1. Why the 'ehanced' implementation DeleteObject: #2, does not need to
inherit unary_function<const T*, void>?
2. Should all my child classes which implement unary_function<const T*,
void> should be converted to 'enhanced implementation (#2)?
Thank you.