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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:13:06+00:00 2026-05-20T16:13:06+00:00

I am trying to base my application on callbacks. The issue that bothers me

  • 0

I am trying to base my application on callbacks. The issue that bothers me the most is that I have to specify what arguments does the lambda function take. My base class that all others extend does specify two basic types. It looks like this:

class Callback
{
    typedef function<void()> Function;
    typedef vector< pair<string, vector<Function>> > CallbackContainer;

public:
    void callback(string); // both types are used

Is it possible to change the arguments of the lambda function (the Function type) just by overriding the type in classes extending this one? Or does the code in the callback method use the original types? If so, can I force the usage of new types without copying and pasting the code? Just to fulfill the DRY.

  • 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-20T16:13:06+00:00Added an answer on May 20, 2026 at 4:13 pm

    Types are not virtual; you cannot “override” them in a derived class.

    From my somewhat limited understanding of what you’re trying to do, I think you should make Callback a template. Something like this:

    template<typename ArgType>
    class Callback
    {
        typedef function<void(ArgType)> Function;
        typedef vector< pair<string, vector<Function>> > CallbackContainer;
    
    public:
        void callback(string); // both types are used
    

    This works only for functions that take exactly one argument, of course. Making it more general in current-day C++ is far from trivial; in C++0x it gets a little bit easier with variadic templates.

    Maybe you could have a look at Boost, though. There’s a good chance that you can use something that is already in there, instead of rolling your own.

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

Sidebar

Related Questions

I am trying to add a custom property to a base form that can
I'm trying to migrate my application from Rails 3.0.7 to Rails 3.1.3. I have
I'm trying to setup a rails application so that I can choose between different
I am trying to follow the Nerd Dinner MVC application as a base to
I'm trying to build an application taking Lync SDK as a base, according to
In my application I am trying to make a virtual attribute that's a date_select
I am trying to built an application which is base on Android Tablet(9.7 inch),
We have changed some base functions we use in an application and I am
I'm trying to define base class, which contains typedef's only. template<typename T> class A
I'm trying to extend some base classes in Python: class xlist (list): def len(self):

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.