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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:27:29+00:00 2026-05-15T02:27:29+00:00

In C#, what I want would look something like this: IDictionary<string, action()> dict =

  • 0

In C#, what I want would look something like this:

IDictionary<string, action()> dict = new Dictionary<string, action()>();

How do I do this in C++? This gives compiler errors:

map<string, void()> exercises;
  • 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-15T02:27:29+00:00Added an answer on May 15, 2026 at 2:27 am

    Use boost::function, a polymorphous wrapper for any object that can be called with your signature (including functions, function objects etc).

    map<string, function<void()>> ...;
    

    Note that the new C++ standard has already included function in <functional>.


    To explain the backgrounds: The only builtin mechanism of this kind in C++ are old C-style function pointers (void (*)()). These are extremely low-level, basically just storing the memory address of a function, and therefore far from even coming close to the power of C#’s delegates.

    You can’t create anonymous functions, neither can you refer to a particular object’s member functions or any variables or data (closures).

    Thus, one often utilizes so called functors which are classes that mimic the behaviour of a function by overloading the operator (). In combination with templates, they are used whereever ordinary function pointers can be used.

    The problem is that these functors often consist of peculiar or anonymous types that can’t be referred to conveniently.

    The function is the coolest way to address them all – Everything that behaves like a function, including cool new lambda-style expressions.

    function<void()> f = []() { cout << "Hello, World"> };
    f();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would want to do something like: >>> lst = [1, 2, 3, 4,
first I want to say that I hope this doesn't look like I am
I am trying to create a winForms user control. But I want would like
I have a Django model that looks something like this: class Person(models.Model): name =
Why you would want to use a switch block over a series of if
I have a special url which I would want only few people to have
Can anyone explain to me why I would want to use IList over List
Why would someone want to use a linked-list over an array? Coding a linked-list
Why would I want to use PHP's filter library? Why wouldn't I? It seems
Is there ever a circumstance in which I would not want to use the

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.