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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:43:31+00:00 2026-06-15T08:43:31+00:00

Is store function pointers with different parameters in a vector of void pointers. unordered_map<string,

  • 0

Is store function pointers with different parameters in a vector of void pointers.

unordered_map<string, vector<void*> > List;

template <typename T>
void Listen(string Name, function<void(T)> Function)
{
    List[Name].push_back(&Function);
}

Then I want to call them, assuming that T is the same type for Fire as used for the Listen.

template <typename T>
void Fire(string Name, T Data)
{
    auto Functions = List[Name];

    for (auto i = Functions.begin(); i != Functions.end(); ++i)
    {
        (function<void(T)>)i)(Data);
    }
}

But I get a compiler error which reads error C2064: term does not evaluate to a function taking 1 arguments in file ...\vc\include\xrefwrap 431 1.

What am I doing wrong?

  • 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-06-15T08:43:33+00:00Added an answer on June 15, 2026 at 8:43 am

    For one, you’re taking the address of a parameter, here:

    List[Name].push_back(&Function);
    

    Then you’re trying to convert an iterator object to a std::function object here:

    (function<void(T)>)i)
    

    What you trying to do can be done, like this, although it’s not pretty, to put it mildly:

    unordered_map<string, vector<void*> > List;
    
    template <typename T>
    void Listen(string Name, function<void(T)> &Function)
    {
        List[Name].push_back(&Function);
    }
    
    template <typename T>
    void Fire(string Name, T Data)
    {
        auto Functions = List[Name];
    
        for (auto i = Functions.begin(); i != Functions.end(); ++i)
        {
          function<void(T)> *ptr = *i;
    
          (*ptr) (Data);
        }
    }
    

    It can break in lot of ways, for example you have no control that the function, registered under some name in Listen is called with the correct argument in Fire – consider calling Listen<int> ("foo", f); and then doing Fire<double> ("foo", 3.14);

    Another approach – just pass closures for callbacks:

    unordered_map<string, std::vector<function<void()> > > List;
    
    void Listen(string Name, function<void()> Function)
    {
        List[Name].push_back(Function);
    }
    
    void Fire(string Name)
    {
        auto Functions = List[Name];
    
        for (auto i = Functions.begin(); i != Functions.end(); ++i)
          (*i) ();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want to store a group of function pointers in a List<(*func)>
I want to store function pointers with different signature in a std::map as a
I'm trying to store member function pointers by templates like this: (This is a
I am trying to store pointers to memberfunctions of different Classes in C++. What
I want to store a function as a class member and call it inside
STORE = { item : function() { } }; STORE.item.prototype.add = function() { alert('test
I want to call a JavaScript function through PHP and store the returned value
I'm using this function to extract files from .zip archive and store it on
I'd like to pre-store a bunch of function calls in a data structure and
Where can I store folder's paths, which can be accessed from every function/variable in

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.