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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:13:23+00:00 2026-05-18T21:13:23+00:00

I have the following classes: class A { public: virtual void myfunc(unsigned char c,

  • 0

I have the following classes:

 class A
{
   public:
        virtual void myfunc(unsigned char c, std::string* dest) = 0;
};

   class B : public class A
{
    public:
        virtual void myfunc(unsigned char c, std::string* dest);
};

void someOtherFunc(const std::string& str,A *pointerFunc)
{
    std::string tmp;
        for_each(str.begin(),
                 str.end(),                 
                 std::bind2nd(std::mem_fun(pointerFunc->myfunc), &tmp));
}

I get the following compilation error:
error: no matching function for call to \u2018mem_fun()\u2019

Do you know why?

  • 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-18T21:13:24+00:00Added an answer on May 18, 2026 at 9:13 pm

    You’re looking for std::mem_fun(&A::myfunc).

    EDIT: You can’t use mem_fun at all here — no overload of mem_fun allows you to make a two argument member function into a functor. You’re going to have to use something like boost::bind/std::tr1::bind (If you have TR1)/std::bind (If you have C++0x) or you’re going to have to write your own functor.

    Note that even if mem_fun was able to do this sort of binding, then std::bind2nd would fail, because bind2nd expects a functor taking two arguments, and binding a member function pointer like this is going to produce a functor with three arguments.

    You have a few ways around this:

    1. Write your own functor that does what you want.
    2. Write an explicit loop instead of std::for_each.
    3. One of the not-yet-standard binder functions I mentioned above (and demonstrated in @David’s answer)
    4. Don’t bother with the virtual function in the first place — make your method accept a plain function pointer and implement things in terms of the function pointer. Of course this only works if myfunc doesn’t depend on members of the class to which it belongs (in which case it shouldn’t have ever been put into a class in the first place)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: public class Person { public String FirstName { set;
I have following classes. class A { public: void fun(); } class B: public
i have the following classes: class A { protected: A *inner; public: .... virtual
I have two classes: public class MyBase { public virtual void DoMe() { }
I have the following hierarchy of classes class classOne { virtual void abstractMethod() =
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have the following class hierarchy in C++: class Base { virtual void apply()
I have the following Entity Framework POCO classes: public class Customer { public int
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
Suppose I have two C++ classes: class A { public: A() { fn(); }

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.