R
robc
hi,
I wrote a container template similar to that below, assuming that as
long as I never called destroy() for a non-pointer instantiation the
compiler would not attempt to generate that method and I would not get
a compile error. e.g:
ThingMap<int*> intPMap;
intPMap.destroy(); //ok for pointer type
ThingMap<int> intMap;
intPMap.clear(); //ok because destroy() not called so not
instantiated
// so no attempt to compile delete of int
Indeed, microsoft visual C++, Sun and HP compilers agreed with me and
compiled this OK. But IBM xlC gives a compile error: the "delete"
operator is not allowed for type "int".
So, am I wrong or is xlC wrong? I can work around this easily enough
but am interested to know.
thanks,
rob
#include <map>
template <class T> class ThingMap
{
public:
..
(other methods....)
..
void clear(){ theMap.clear(); }
void destroy()
{
for(stl::map<T>::iterator it=theMap.begin();
it!=theMap.end();++it)
delete it->second;
clear();
}
private:
stl::map<T> theMap;
};
I wrote a container template similar to that below, assuming that as
long as I never called destroy() for a non-pointer instantiation the
compiler would not attempt to generate that method and I would not get
a compile error. e.g:
ThingMap<int*> intPMap;
intPMap.destroy(); //ok for pointer type
ThingMap<int> intMap;
intPMap.clear(); //ok because destroy() not called so not
instantiated
// so no attempt to compile delete of int
Indeed, microsoft visual C++, Sun and HP compilers agreed with me and
compiled this OK. But IBM xlC gives a compile error: the "delete"
operator is not allowed for type "int".
So, am I wrong or is xlC wrong? I can work around this easily enough
but am interested to know.
thanks,
rob
#include <map>
template <class T> class ThingMap
{
public:
..
(other methods....)
..
void clear(){ theMap.clear(); }
void destroy()
{
for(stl::map<T>::iterator it=theMap.begin();
it!=theMap.end();++it)
delete it->second;
clear();
}
private:
stl::map<T> theMap;
};