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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:28:32+00:00 2026-05-22T11:28:32+00:00

Why my VS2010 can’t compile this code: #include <functional> #include <vector> int main() {

  • 0

Why my VS2010 can’t compile this code:

#include <functional>
#include <vector>
int main()
{
    std::vector<int> vec;
    std::bind(&std::vector<int>::push_back, std::ref(vec), 1)();
    return 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-05-22T11:28:32+00:00Added an answer on May 22, 2026 at 11:28 am

    Try this:

    struct push_back {
        void
        operator()(std::vector<int>& vector, int i) const
        {
            vector.push_back(i);
        }
    };
    
    // somewhere else:
    std::vector<int> vec;
    std::tr1::bind(push_back(), std::tr1::ref(vec), 1)();
    

    With C++03 note that push_back cannot be a local type; with C++11 it can but it would be more idiomatic (and completely equivalent) to use a lambda.

    In all likeliness your implementation provides overloads for std::vector<T>::push_back and thus its address would have to be disambiguated. If this is what happened, your compiler should have provided you with an appropriate error message. In all cases, you should explain what you mean by “it’s not possible”.


    The point is not to use such helper
    functions. – magenta

    Then why didn’t you put it in the question? I can’t read your mind.

    You can also try this:

    std::vector<int> vec;
    void (std::vector<int>::*push_back)(int const&) = &std::vector<int>::push_back;
    std::tr1::bind(push_back(), std::tr1::ref(vec), 1)();
    

    Which I believe is not guaranteed to success.

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

Sidebar

Related Questions

So on my VS2010 I can compile code like : boost::shared_ptr<boost::thread> internal_thread; boost::packaged_task<void> internal_task_w(boost::bind(&thread_pool::internal_run,
Can I change the code, so that the VS2010 compiler's error message points to
I'm using VS2010 RC while targeting .NET 3.5. I can run code analysis via
I've got a solution in VS2010 where I can't get the code coverage working,
This is in VS2010 ... I can't figure this out, but my assembly is
I have a ASP.NET MVC2 project in VS2010 that can be deployed in two
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
Can you use Ninject 2.0 with VS2010 RC1?
Intellisense popup in VS2010 is driving me crazy. I can only see 9 items
After installing VS2010 yesterday - (both VS2005 and VS2010 installed), I can't find 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.