Re: multimap and abstract class
asOn Aug 20, 10:30 am, Barry <bg...@yahoo.com> wrote:
I have an abstract class called "Event" and a number of
classes which inherit from it, including "NoteOn" and
"NoteOff".
I am now attempting to create a multimap called EventList, as
follows -
#ifndef EVENT_LIST_H
#include <map>
#include "Event.h"
class EventList : public std::multimap<double,Event>
{
public:
EventList(void);
virtual ~EventList(void);
};
#endif
#ifndef EVENT_H
class Event
{
public:
Event(void);
virtual void dummy() = 0;
virtual ~Event(void);
};
#endif
but this isn't allowed according to my compiler because
'Event' : cannot instantiate abstract class.
I don't understand why I get this fail since I haven't even
created a EventList object yet.
What is the issue here?
You've used std::multimap< double, Event > in a context where a
complete type definition is required, so you've instantiated the
class template. The standard says that this is undefined
behavior if you do it over a type which doesn't support a
minimum of required operations: copy construction and
assignment, for example. An abstract class doesn't fit the
bill, so the compiler can do anything it wants. Good compilers
(or library implementations) generate a compile time error.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34