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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:05:16+00:00 2026-05-14T21:05:16+00:00

I would like to call a member through lambda::bind. Unfortunately I have got two

  • 0

I would like to call a member through lambda::bind. Unfortunately I have got two members with the same name but different return types.
Is there a way to help the lambda::bind to deduce the right return type for a member function call? (bind works fine with explicit return type deduction)

#include <vector>
#include <iostream>
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;
using namespace boost;

struct A
{
  A (const string & name) : m_name(name) {}

  string &        name ()         { return m_name; }
  const string &  name () const   { return m_name; }

  string m_name;
};

vector<A> av;

int main () 
{
  av.push_back (A ("some name"));

  // compiles fine
  find_if(av.begin(), av.end(), bind<const string &>(&A::name, _1) == "some name");

  // error: call of overloaded 'bind(<unresolved overloaded function type>, const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)' is ambiguous
  find_if(av.begin(), av.end(), lambda::bind(&A::name, lambda::_1) == "some name");

  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-14T21:05:17+00:00Added an answer on May 14, 2026 at 9:05 pm

    The different return types is a red herring. The issue is with const overloading of method (i.e. you would have the same problem no matter what the relative return types are). This is problem is documented here and here, and using the return type-specified form is not the recommended solution (will work most of the time, except some version of MSVC).

    The problem is that taking the address of an overloaded member function (either const overloaded or parameter overloaded) is ambiguous, so some extra information is required.

    The solution is to cast the function pointer, which lets the compiler know exactly which of the overloaded functions you want, The cleanest way to do this I’ve found is to typedef the function pointer types, since otherwise the lines get a bit nasty. Here’s an example with your code (compiles clean gcc 4.3.4):

    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <boost/bind.hpp>
    #include <boost/lambda/lambda.hpp>
    #include <boost/lambda/bind.hpp>
    
    using namespace std;
    using namespace boost;
    
    struct A
    {
      A (const string & name) : m_name(name) {}
    
      string &        name ()         { return m_name; }
      const string &  name () const   { return m_name; }
    
      string m_name;
    };
    
    vector<A> av;
    
    //function pointer for non-const version
    typedef string& (A::*NameFuncType)(void);
    
    //function pointer for const version
    typedef const string& (A::*NameConstFuncType)(void) const;
    
    int main () 
    {
      av.push_back (A ("some name"));
    
      //'correct' way to call const version w/ boost::bind
      find_if(av.begin(), av.end(), 
        bind(static_cast<NameConstFuncType>(&A::name), _1) == "some name"
      );
    
      //call for non-const version w/ boost::lambda::bind
      find_if(av.begin(), av.end(), 
         lambda::bind(static_cast<NameFuncType>(&A::name), lambda::_1) == "some name"
      );
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains a member object. I would like to call
I have a controller action which I would like to call another controller action.
I have a data set that that I would like to call in a
I would like to have one background thread which will copy the files through
I have an object: map<A*, string> collection; I would like to call the map::find
I would like to know if its possible to call a non-const member function
I would like to call python script files from my c++ program. I am
I would like to call Perl script files from my c++ program. I am
I would like to call my unmanaged C++ libraries from my C# code. What
I would like to call C# service with using PHP, anyone know how to

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.