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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:06:30+00:00 2026-05-26T17:06:30+00:00

I am sorry for the long text but I would like to present the

  • 0

I am sorry for the long text but I would like to present the problem I am trying to solve with this as well as the actual problem. Maybe I will be pointed to another, possibly better approach.

I would like to create an eventtriggerred handler system. I will have several handler modules. The basic idea is that during initialization these modules will register for events they handle (register(module,eventItGetsCalledFor)) in a eventlist. In the case an event is triggered, it is looked up in the eventlist and all modules listed there are created and run. To achieve this all the modules have an interface.

My two questions are:

  1. Since I only want to instantiate the modules upon the actual event I need either a way to store a pointer to the constructor (“virtual constructor”), since there are no virtual constructors as far as I know I go with a Factory method which I would like to add to the interface. The classic approach I know of would be:

    class myInterface {
    public:
       ...
       static virtual *myInterface builder() = 0; //is static (pure) virtual possible?
    };
    
    class example : public myInterface {
    public:
       ...
       static virtual *myInterface builder() { return new example(); }
    };
    

    I would then have to store pointers to the builder() functions in the event list and execute the functions in case the event occurs to create the objects. I am wondering if there is a way arround writing static virtual *myInterface builder() { return new example(); } for every example module.
    A template approach would be to put it like this:

    template
    static virtual *myInterface builder() { return new T(); }

    However I dont like it to much since I would have to write the following to register a module for an event:

    register(eventName,builder())

    considering that I would like to create only one static register function in each module like so:

    class example: public myInterface {
        static void registerMe {
            register(event1,builder<example>());
            register(event2,builder<example>());
            ...
            register(eventn,builder<example>());
        }
    };
    

    it would be way more convenient if a call like register(event) would be sufficient.
    i could add register(event) to the interface, but I dont want to rewrite the register function for every template which would read

    void register(event) { getListForEvent(event).pushBack(builder<example>()); }
    

    (the builder-template instantiation parameter varies), and making it a template itself is not to good either, since this brings me back to writing register<myclass>() over and over.

    So is there a more conviniant way?
    (During the pondering and writing of this I came up with inheriting from a template class. If polimorphism works with template classes with different instantiation parameters. Otherwise I have to use an Interface class, wrap it in a template and Inherit from that )

  2. The second question is I have different classes derived from my interface class. However they have members which are not defined in the Interface. I would like to store a functionpointer to a member function, how do I do this? The type has to accept different base classes, but the rest of the function signature is the same (see example below)

    class A : public interface {
         void myFunc()
    };
    
    class A : public interface {
         void yourFunc()
    };
    
    whatType* a = &A::myFunc;
    whatType* b = &B::yourFunc;
    
  • 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-26T17:06:30+00:00Added an answer on May 26, 2026 at 5:06 pm

    //is static (pure) virtual possible?

    No

    CRTP (Curiously recurring template pattern) to the rescue

    template <class Derived>
    class myInterface {
    public:
        ...
        virtual *myInterface builder() = 0; 
    
        Derived* buildDerived() 
        { 
             return dynamic_cast<Derived*>(builder());
        }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this post is a long one sorry for that but the problem is complex
Sorry for a long question and not a very descriptive title, but my problem
Sorry for this long post. The question is however small but requires full detail.
[Sorry for long question but it is necessary to explain the problem] I am
Sorry for a long question but here goes. I am trying to modify the
Sorry for long winded post. I am trying to understand UIScrollView and running into
sorry for the long question. I am trying to ajax post to collect a
Firstly sorry for the long piece of code pasted below. This is my first
This question has disturbed me for a long time. Sorry if it is a
Sorry for the long post, but most of it is code spelling out my

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.