In article <4ba31cbc$0$2858$ba620e4c@news.skynet.be>,
olivier.scalbert@algosyn.com says...
Hello,
Let's say I have a base class Event and some sub classes EventType1,
EventType2, ...
1)
I would like to have a collection (vector or list for example) of a mix
of EventType1, EventType2, ...
I think I have to create a vector<Event*> and starts playing with "new".
And of course, I will forget the "delete" !
Are there any other options, to keep the code clean ?
You can make many higherarchies that you have control over value types
with some work. It involves the use of the handle/body idiom:
// event.h
struct event
{
// NVI
typedef ? event_type_id;
event_type_id event_type() const { return pimpl->event_type(); }
//...
event(event_type_id id);
struct impl
{
virtual event_type_id event_type() const = 0;
// ...
};
private:
std::auto_ptr<impl> pimpl;
};
Your impl class is missing a virtual destructor.