A
Adrian
Lint (rightly I believe) complains that deque's destructor is not
virtual. So will the following code cause any problems?
If I do not derive from Container does that stop problems?
Do I manually have to call deque's destructor from Containers to make
sure?
Adrian
#include <stdexcept>
#include <deque>
class SomeClass
{
};
typedef std::deque<SomeClass *> list_t;
class Container : private list_t
{
public:
Container() {};
using list_t:op_front;
using list_t::front;
using list_t::empty;
using list_t::size;
void clear()
{
for(const_iterator i=begin(); i!=end(); ++i)
{
delete (*i);
}
list_t::clear();
};
void push_back(SomeClass * const obj)
{
if(size()>10)
{
throw std::runtime_error("much to big");
}
list_t:ush_back(obj);
};
~Container()
{
clear();
}
private:
Container(const Container &);
Container &operator=(const Container &);
};
int main(int argc, char *argv[])
{
Container container;
for(int i=0; i<9; ++i)
{
container.push_back(new SomeClass());
}
return 0;
}
virtual. So will the following code cause any problems?
If I do not derive from Container does that stop problems?
Do I manually have to call deque's destructor from Containers to make
sure?
Adrian
#include <stdexcept>
#include <deque>
class SomeClass
{
};
typedef std::deque<SomeClass *> list_t;
class Container : private list_t
{
public:
Container() {};
using list_t:op_front;
using list_t::front;
using list_t::empty;
using list_t::size;
void clear()
{
for(const_iterator i=begin(); i!=end(); ++i)
{
delete (*i);
}
list_t::clear();
};
void push_back(SomeClass * const obj)
{
if(size()>10)
{
throw std::runtime_error("much to big");
}
list_t:ush_back(obj);
};
~Container()
{
clear();
}
private:
Container(const Container &);
Container &operator=(const Container &);
};
int main(int argc, char *argv[])
{
Container container;
for(int i=0; i<9; ++i)
{
container.push_back(new SomeClass());
}
return 0;
}