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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:09:56+00:00 2026-05-18T04:09:56+00:00

If I have a base class: class Base { public: virtual void Test()=0; };

  • 0

If I have a base class:

class Base 
{
public:
virtual void Test()=0;
};

and, in a dynamically loaded module (.so/.dll), I implemented a class derived from this:

class SomethingFromBase : Base 
{
...
};

and, the user, once this library is loaded, asks to create an instance of SomethingFromBase (let’s say we get the name from cin.), and, we have no knowledge of SomethingFromBase (i.e, no way to just do if(inputstr == "SomethingFrombase") { ... } is there any way to create an instance of SomethingFromBase?

I’m fairly certain this is impossible in (standard) C++, but, I’m always hoping SO will surprise me!

If this is possible with the addition of some library, I’d still like to know about it.
Thanks!

Edit: See cdhowie’s answer. Guides to implementing this technique:
http://www.linuxjournal.com/article/3687?page=0,1
http://www.abstraction.net/ViewArticle.aspx?articleID=67

  • 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-18T04:09:56+00:00Added an answer on May 18, 2026 at 4:09 am

    You typically achieve this by required that plugin libraries define some global variable of a struct type that contains pointers to various functions you can call. (Like setup, teardown, etc.) During the setup function, they would call back into your application to some “register” function where they could pass in a string representing the name of the class, and a factory function pointer that will create an instance when executed.

    You stash this away in some map, and when the user enters a string, you look at the map to see if there is a factory function registered. If so, just call it.

    So this is not “true” reflection, but you can manually hack it to some degree. See, for example, Pidgin, which allows the specification of protocol plugins that may supply many entries in the protocol list.

    EDIT: Here is a nifty guide to implementing something similar. I’m more of a C person, so I can’t vouch for it being truly awesome or anything, but at first glance it looks good. I’ve done similar stuff in C on Linux, and the basic approach works pretty well.

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

Sidebar

Related Questions

Suppose I have a base and derived class: class Base { public: virtual void
I have 2 classes: class Base { public: virtual int Foo(int n); virtual void
I have code like this: namespace N { class B { public: virtual void
I have an abstract base class and derived class: type TInterfaceMethod = class public
If I have a base class such that public abstract class XMLSubscription <T extends
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
I have a base class with an optional virtual function class Base { virtual
I have a base class that represents a database test in TestNG, and I
I have the following class structure that I need to unit test: public interface
#include<iostream> using namespace std; class Abs { public: virtual void hi()=0; }; class B:public

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.