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

The Archive Base Latest Questions

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

I would like to implement, in c++, a class b where it would be

  • 0

I would like to implement, in c++, a class b where it would be possible to do some kind of iteration through a member set encapsulating the type of that iterator. Like:

b_object.for_each_x_do(function_f);

so function_f would get everyone of the x members and do anything. Let’s say:

void function_f(x_member_type x){ cout << x << endl; }

Ok. So I’m trying to achieve that through a code like:

class b{
    int *x;
public:
    void foreach_x_do(void (*f)(int)){
            while(*x++)  // or any kind of iteration through x
                    f(*x);
    }
};

class a{
    b b_inst;
public:
    void f(int x) {  }     
    a(){
            b_inst.foreach_x_do(f); // by mistake it was b_inst.foreach_x_do(f)(), however this wasn't the point at all. 
    }
    ~a(){}
};

int main(){} 

However, I’m getting this error, compile-time:

fp.cpp: In constructor ‘a::a()’:
fp.cpp:17: error: no matching function for call to ‘b::foreach_x_do(<unresolved overloaded function type>)’
fp.cpp:6: note: candidates are: void b::foreach_x_do(void (*)(int))

Anybody can help getting it to compile?

  • 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:27:25+00:00Added an answer on May 22, 2026 at 11:27 am

    It should just be:

    b_inst.foreach_x_do(f);
    

    You also need to make f static, not a non-static member method since the original signature for your foreach_x_do function is for a stand-alone function pointer, not a pointer-to-member-function. So i.e.,

    static void f(int x) {  } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to implement a simple class (in Java) that would allow me to
I would like a class to implement an interface, I do not want to
I would like to pass values into the constructor on the class that implements
I have a class that implements multiple interfaces. I would like to register these
I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
I have a thread that is doing some processing. I would like to be
I have a smart pointer type, and would like to construct an object that
On Android, I would like to create a button that contains some other Views.
I would like to put some code in module that throws an error if
In java <1.5, constants would be implemented like this public class MyClass { public

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.