Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:34:13+00:00 2026-05-26T15:34:13+00:00

For example: abstract class goal class priority class childgoal multimap<priority, goal> mm; mm.insert(make_pair(priority(), childgoal());

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:34:13+00:00Added an answer on May 26, 2026 at 3:34 pm

    You can make a map of pointers:

    #include <memory>
    #include <map>
    
    class Base { };
    class Derived1 : public Base { };
    class Derived2 : public Base { };
    
    typedef std::shared_ptr<Base> MyPtr;
    typedef std::multimap<Key, MyPtr> MyMap;
    
    int main()
    {
      MyMap m { { Key(1), MyPtr(new Derived1) }, { Key(2), MyPtr(new Derived2) } };
    }
    

    Uniform initialization syntax requires C++11 support. In older versions, you can insert instead:

    m.insert(MyMap::value_type(Key(1), MyPtr(new Derived1)));
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the PHP manual , a class like this: abstract class Example {}
For example, let's say this is my abstract class: abstract class A{ int x;
I'm trying to achieve the following goal: Using this general singleton class: abstract class
Given this highly simplified example: abstract class Animal { } class Dog : Animal
Given this example: abstract class Base { type Value } case object Foo extends
For example, I have a class called Clothing that inherits from a abstract class
To put it simply as an example, public abstract class AbstractFellow { protected Thing
Consider the following (simplified) example: abstract class Bar[T] { val f: PartialFunction[T, T] val
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
To illustrate my point, here an example: abstract class Wrapper[A](wrapped: A) { protected def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.