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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:47:52+00:00 2026-05-28T07:47:52+00:00

I’m currently trying to build a class hierarchy automatically by using C++ templates. The

  • 0

I’m currently trying to build a class hierarchy automatically by using C++ templates. The final result is a message handler class that provides handler functions for all possible messages, given in a typelist.

However when inheriting from that class hierarchy and trying to implement the handler function to actually do the application code for some types only, C++ isn’t calling the function from the base class.

The following is a minimal and complete example what I’m trying to achieve. It doesn’t compile because C++ complains about not finding an overload for handle( const B& ).

#include <iostream>
#include <typeinfo>

// Typelist.
struct None {};

template <class H, class T = None>
struct Typelist {
    typedef H Head;
    typedef T Tail;
};

template <class TL>
struct Handler : public Handler<typename TL::Tail> {
    using Handler<typename TL::Tail>::handle;

    virtual void handle( const typename TL::Head& obj ) {
        std::cout << "Not handled! " << typeid( typename TL::Head ).name() << std::endl;
    }
};

template <>
struct Handler<None> {
    virtual void handle() {}
};

struct A {};
struct B {};

typedef Typelist<A, Typelist<B> > MsgList;

struct MyHandler : Handler<MsgList> {
    void handle( const A& a ) {
        std::cout << "A!" << std::endl;
    }
};

int main() {
    MyHandler handler;

    A a;
    B b;

    handler.handle( a );
    handler.handle( b );
}
  • 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-28T07:47:53+00:00Added an answer on May 28, 2026 at 7:47 am

    You need to use handle from you Handle<MsgList> in your MyHandler class

    using Handler<MsgList>::handle;
    

    Right now it is hidden and do not overload the name handle in MyHandler class. And taking into account the code of the Handler, you know this 🙂

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

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.