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

  • Home
  • SEARCH
  • 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 8512207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:13:04+00:00 2026-06-11T04:13:04+00:00

std::vector<int> v1; std::function<void(const int&)> funct = static_cast<std::function<void(const int&)>>(std::bind( &std::vector<int>::push_back, &v1, std::placeholders::_1)); This gives me

  • 0
std::vector<int> v1;
std::function<void(const int&)> funct = 
static_cast<std::function<void(const int&)>>(std::bind(
                                            &std::vector<int>::push_back,
                                            &v1,
                                            std::placeholders::_1));

This gives me no matching function for call to bind.

I am able to do this though:

threadPool.push_back(std::thread(runThread<lazyFunct>,
                     std::bind(&LazySkipList<int>::add,
                     &lsl, std::placeholders::_1), 0, 1000000, 1000000));

I am using Xcode 4.4 with llvm C++11 support.

  • 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-11T04:13:05+00:00Added an answer on June 11, 2026 at 4:13 am

    The problem is std::vector::push_back() is overloaded with the two possible type signatures:

    void push_back(const T& value);
    void push_back(T&& value);
    

    As such, the template parameter to std::bind() cannot be inferred. However, you can declare the template parameter explicitly:

    std::bind<void(std::vector<int>::*)(const int&)>(&std::vector<int>::push_back, &v1, std::placeholders::_1);
    

    This resolves correctly.

    Of course, at this point it might be simpler just to use a lambda:

    auto func = [&](int i){ v1.push_back(i); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void PrintNow(const std::vector<int> &v) { std::cout << v[0] << std::endl; } std::vector<int>().push_back(20); // this
how to remove function that bound to member function of this object : std::vector<std::function<void(int)>>
std::vector<const int> vci; vci.push_back(1); vci[0] = 2; With the element type being const int
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>
Consider this: std::vector<int*> v(1, 0); This compiles fine with VC++10 (no warnings even at
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>>
Example: I have a function that works with vectors: double interpolate2d(const vector<double> & xvals,
I'll start with the code: typedef std::vector<unsigned char> CharBuf; static const int RCV_BUF_SIZE =
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,

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.