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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:33:31+00:00 2026-06-03T20:33:31+00:00

Is it possible to create an std::vector that can hold an std::function with any

  • 0

Is it possible to create an std::vector that can hold an std::function with any signature?
(The function arguments would all be pre-bound.)

I tried std::vector<std::function<void()> >, since if I only have one std::function of that type I can bind any function to it.

This does not seem to work inside a vector: if I try to add a function with std::bind to the vector that has a signature other than void(), I get:

No matching member function for call to 'push_back'

Is there a way to do this?

Edit:

I just remembered that std::function<void()> does allow you to bind any function that returns void as long as the arguments are pre-bound with std::bind, it does not allow you to bind any signature though, but for my purposes it’s generic enough, so the following works:

class A
{
public:
    void test(int _a){ return 0; };
};

A a;
std::vector<std::function<void()> > funcArray;
funcArray.push_back(std::bind(&A::test, std::ref(a), 0));
  • 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-03T20:33:32+00:00Added an answer on June 3, 2026 at 8:33 pm

    This should work:

    #include <iostream>
    #include <functional>
    #include <vector>
    
    void hello() { std::cout << "Hello\n"; }
    void hello2(const char * name) { std::cout << "Hello " << name << '\n'; }
    
    int main()
    {
    
        std::vector<std::function<void()>> v;
        v.push_back(hello);
        v.push_back(std::bind(hello2, "tim"));
        v[0]();
        v[1]();
    }
    

    How are you doing it?

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

Sidebar

Related Questions

Possible Duplicate: How can I create cartesian product of vector of vectors? I'm having
I want to create an std::vector object (or any other standard or custom container
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Is it possible to create chat rooms dynamically with socket.io ? All the examples
Is it possible to use std::next_permutation() to permutate the elements of a vector of
If I create a std::vector with the default allocator like this: vector<int> myVec =
I want to create a big std::vector so operator[] should receive long long rather
I tried to create a container for posible metadata that can be attached to
I would like to know if it is possible to create an actual functor

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.