For example:
abstract class goal
class priority
class childgoal
multimap<priority, goal> mm;
mm.insert(make_pair(priority(), childgoal());
I get the error:
cannot declare field 'std::pair<priority, goal>::second'
to be of abstract type 'goal'
If I remember correctly, Pair uses the default constructor to create second before assigning, which is the cause of the distress. I may be incorrect, but it would explain the error.
How do I get around this… how can i accomplish inserting into a multimap (or probably map for that matter) when one of the types is abstract?
You can make a map of pointers:
Uniform initialization syntax requires C++11 support. In older versions, you can insert instead:
If nobody else needs the mapped objects, you might get away with a
std::unique_ptr<Base>instead. A simple matter of changing the typedef.