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 849839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:09:58+00:00 2026-05-15T07:09:58+00:00

how can I insert my own class objects into ptr_map from boost. The objects

  • 0

how can I insert my own class objects into ptr_map from boost. The objects are templated so I can’t use some static typename in the map. So I did:

ptr_map<string, any> someMap;

My class inherits the boost::noncopyable.

someMap.insert("Test", new MyClass<SomeTemplate>());

The error is: error: no matching function for call to ‘boost::ptr_map.


UPD:
I’d prefer to make some wrapper and don’t use the boost::any. So:

class IWrapper { };
class MyClass : public IWrapper { };

ptr_map<string, IWrapper> someMap;
someMap.insert("Test", new MyClass<SomeTemplate>());

Why it won’t work (the same error)? I could pass the inherited class into parent interface. What’s wrong?

  • 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-15T07:09:59+00:00Added an answer on May 15, 2026 at 7:09 am

    By far, most of the time problems of this type ought to be solved with a common base class. This is the case when all of the classes will be used similarly. Runtime polymorphism.

    I have seen legitimate reasons to not allow a common base class. In this case boost::variant will generally server better as there are still methods to treat each item uniformly (a visitor). Compile time polymorphism.

    I have never seen a legitimate use for for boost::any. I’m not saying there isn’t one, but it is so rare that I’ve never encountered it.


    That said, try this.

    std::map<std::string,boost::any> someMap;
    boost::any insanity = new MyClass<SomeTemplate>;
    someMap.insert("Test",insanity);
    

    or

    boost::ptr_map<std::string,boost::any> someMap;
    boost::any* ive_lost_it = new boost::any( new MyClass<SomeTemplate> );
    someMap.insert("Test", ive_lost_it );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can insert a row by using code below. USE pmdb; INSERT INTO md5_tbl
How can I configure membership provider to insert data on my own database
EntityManager.merge() can insert new objects and update existing ones. Why would one want to
Is there a way that I can insert values into a VB.NET Dictionary when
I need to know how I can insert data inside objects inside an array
I am trying to work out how I can insert the string End into
I'm using adapter.InsertCommand to insert some data into a table. The only problem is
For a class assignment, we can't use any of the languages bultin types, so
I tried to create my own Border class and then insert it in my
I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a

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.