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

  • Home
  • SEARCH
  • 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 9254993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:36:40+00:00 2026-06-18T11:36:40+00:00

i have two independent class hierarchies, starting at BaseClass1 , BaseClass2 this is what

  • 0

i have two independent class hierarchies, starting at BaseClass1, BaseClass2

this is what I want to do:

struct BaseClass1 {
  virtual void obtain_map(std::map<int,BaseClass2> &map) = 0;
}

Subclasses of BaseClass1 override the obtain_map. But the problem is that those sublcasses should be able to use subclasses of BaseClass2 in the map parameter. (So in this sense, subclasses of the two “independent” hierarchies are actually related, or rather can be if the subclass designers want)

How can I accomplish this, or am I forced to create my own map class from scratch?

  • 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-06-18T11:36:41+00:00Added an answer on June 18, 2026 at 11:36 am

    If you derive your classes like so and use pointer as the second map template parameter (a smart pointer like std::unique_ptr will save you some memory management trouble):

    struct BaseClass1 {
        virtual void obtain_map(std::map<int, std::unique_ptr<BaseClass2>> &map) = 0;
    };
    struct DerivedClass1 : public BaseClass1 {
        virtual void obtain_map(std::map<int, std::unique_ptr<BaseClass2>> &map) override
        {
        }
    };
    

    You can still pass in maps with derived versions of BaseClass2 as the second type:

    struct DerivedClass2 : public BaseClass2;
    // ...
    
    std::map<int, std::unique<DerivedClass2>> mdc2;
    DerivedClass1 dc1;
    dc1.obtain_map(mdc2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two independent classes: class Foo { int bar; } class Baz
I'm going to have two independent programs (using SqlAlchemy / ORM / Declarative) that
I have a project that uses two independent Android libraries. Each of them contains
I have a DotNetNuke database and an independent C# webservice. I receive two strings
I have two classes (MVC view model) which inherits from one abstract base class.
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have a XAML form that I would like two independent features threaded out
I have two classes (class A and B) both marked with [Binding]. Currently I'm
I have a library class which contains two methods, say, Login() and NavigateToPage(). Now,
Let's say I have the following two class definitions (only the access specifier for

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.