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;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Try this:
With C++03 note that
push_backcannot 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_backand 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”.Then why didn’t you put it in the question? I can’t read your mind.
You can also try this:
Which I believe is not guaranteed to success.