Thomas Wegener
2006-01-19 16:11:20 UTC
I create the items for the std:map with new and before I clear the map I
delete all items, deleteSecond() in the following sample. Unfortunately my
application crash sometimes during map::clear or during new allocation of
items. I assume somthing is wrong in my template.
Somebody any idea what can be wrong?
template <class S, class T>
class MyMap : public std::map< S*, T*, std::less<S*> >
{
public:
~MyMap() {
deleteSecond();
}
void deleteSecond() {
for( iterator i = begin(); i != end(); ++i ) {
delete (*i).second;
(*i).second = 0;
}
}
void clear() {
deleteSecond();
std::map< S*, T*, std::less<S*> >::clear();
}
T * get( const S * key ) {
iterator i = find( const_cast<S*>( key ) );
return end() == i ? 0 : (*i).second;
}
bool put( S * a, T * b ) {
return insert( value_type( a, b ) ).second;
}
};
Thanks Thomas
delete all items, deleteSecond() in the following sample. Unfortunately my
application crash sometimes during map::clear or during new allocation of
items. I assume somthing is wrong in my template.
Somebody any idea what can be wrong?
template <class S, class T>
class MyMap : public std::map< S*, T*, std::less<S*> >
{
public:
~MyMap() {
deleteSecond();
}
void deleteSecond() {
for( iterator i = begin(); i != end(); ++i ) {
delete (*i).second;
(*i).second = 0;
}
}
void clear() {
deleteSecond();
std::map< S*, T*, std::less<S*> >::clear();
}
T * get( const S * key ) {
iterator i = find( const_cast<S*>( key ) );
return end() == i ? 0 : (*i).second;
}
bool put( S * a, T * b ) {
return insert( value_type( a, b ) ).second;
}
};
Thanks Thomas