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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:48:00+00:00 2026-05-24T12:48:00+00:00

I have some base class A , and some number of inherited classes: class

  • 0

I have some base class A, and some number of inherited classes:

class B : public A
class C : public A
class D : public A

I have function with parsing some config file, which use name in config call:

void do_smth<B>(...);
void do_smth<C>(...);
void do_smth<D>(...);

I have map<A*> objs; and in those functions happend:

void do_smth<T>(...)
{
  T *control = new T();
  ...
  objs[name] = T;
}

So i have map of pointers to A. In other function I got name, and i need to get value stored in B,C or D classes.
Problem is that i can’t add virtual function to any class which will return those value, because of A,B,C,D from library and B have function value(), C – text(), D – currentValue() etc. And i need function get_value() which will return result of value(), text(), currentValue() depending on class?
What can you advise me to solve my problem?

I see 2 ways:

1) I can write function from pointer to classes B,C,D and call function like that get_value((B*)objs[name]); but i think it’s not good.

2)I can create boost::bind object with function i need at the create B,C,D variable.

What way will be better, or could you advise me smth better?

  • 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-24T12:48:01+00:00Added an answer on May 24, 2026 at 12:48 pm

    So you have

    A* a;
    

    and don’t know what type it is. Try dynamic_cast:

    B* b = dynamic_cast<B*>(a);
    if ( b ) 
        return b->value();
    //C and D the same way
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume some domain and view objects (that have no common base class) public class
I have a base and derived class. The base class constructors have some static
I am writing some unit test and I have a unit testing base class
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have a number of classes that represent various computer components, each of which
Given a base class where I have some logic that must run before and
I have set of classes. Each class is inherited from another class. The relationship
I have a base class looking like this: public class BaseController : Controller {
When I declare some base styles for my site I have used to do
I have written some general functions to convert between decimal and any other base-n

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.