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

The Archive Base Latest Questions

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

Possible Duplicate: Using bind1st for a method that takes argument by reference I have

  • 0

Possible Duplicate:
Using bind1st for a method that takes argument by reference

I have the following traditional C++03 loop (using auto for stack overflow space efficiency only):

for (auto it = some_vector.begin(); it != some_vector.end(); ++it)
{
    foobar.method(*it);
}

In C++11, I managed to rewrite this into the following for_each invocation which works perfectly well:

std::for_each(some_vector.begin(), some_vector.end(),
              std::bind(&Foobar::method, std::ref(foobar), _1));

(Of course I could just use a lambda in C++11, but that’s not the point.) Unfortunately, std::bind is not part of C++03, so I tried simulating it with std::bind1st and std::mem_fun_ref:

std::for_each(some_vector.begin(), some_vector.end(),
              std::bind1st(std::mem_fun_ref(&Foobar::method), std::ref(foobar)));

But this triggered a C2535 error in Visual Studio (“member function already defined or declared”):

// inside class binder1st in header xfunctional

result_type operator()(const argument_type& _Right) const
{   // apply functor to operands
    return (op(value, _Right));
}

result_type operator()(argument_type& _Right) const
{   // apply functor to operands   <--- ERROR C2535 HERE
    return (op(value, _Right));
}

Is this a const-correctness bug in Visual Studio, or have I done something wrong?

Also, std::ref does not seem to be part of C++03. Is there any workaround?

  • 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-28T01:41:33+00:00Added an answer on May 28, 2026 at 1:41 am

    Why not simply use std::mem_fun? It expects a pointer as the first parameter, as such:

    #include <functional>
    #include <algorithm>
    #include <vector>
    
    struct foo{
        void method(int){}
    };
    
    int main(){
        std::vector<int> v;
        foo f;
        std::for_each(v.begin(), v.end(),
            std::bind1st(std::mem_fun(&foo::method), &f));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Using A* to solve Travelling Salesman Problem I have recently learned that
Possible Duplicate: Adding HTML entities using CSS content I have the following setup CSS:
Possible Duplicate: Casting vs using the ‘as’ keyword in the CLR Which method is
Possible Duplicate: Using ApplicationSettings to store Checked property for WinForms RadioButtons I have three
Possible Duplicate: Tab behavior using jQuery Imagine that there are many text boxes in
Possible Duplicate: SELECT INTO using Oracle I have one table in my oracle database.
Possible Duplicate: VB Using colons to put two statements on same line I have
Possible Duplicate: Using global exception handling with “setUncaughtExceptionHandler” and “Toast” I have implemented UncaughtExceptionHandler
Possible Duplicate: casting vs using the 'as' keyword in the CLR I have seen
Possible Duplicate: Using var outside of a method I've searched for this a bit,

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.