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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:19:44+00:00 2026-05-24T04:19:44+00:00

I have a class X which has this method: void setRxHandler(void (*h)(int)); And I

  • 0

I have a class X which has this method:

void setRxHandler(void (*h)(int));

And I want to pass to it a member function that exists in instances of class Y.

void comm_rxHandler(int status);

I tried the following:

x.setRxHandler(comm_rxHandler) 

But it get the following compile error (I’m using Qt):

error: no matching function for call to
‘X::setRxHandler(< unresolved overloaded function type>)’

So, how can I do that?

I noticed if I declare comm_rxHandler (class Y) as static, I have no errors. But I want comm_rxHandler as a non-static method. Also I want setRxHandler method (class X) to be generic and not class-specific. So I can’t declare that method as:

setRxHandler(void (Y::*h)(int))

How to do that? Can you help me on this?

Thanks!

  • 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-24T04:19:45+00:00Added an answer on May 24, 2026 at 4:19 am

    As it is now, the setRxHandler prototype takes a pointer to a function that doesn’t return anything and takes an int. As you have noticed, this won’t work with member functions because they can’t be called like a normal function (you have to handle the this pointer as well, which means having an instance of that class to call the method on).

    To make it both work with member functions and non-specific (generic), you have to either make a base class and have all classes you want to use setRxHandler with derive from that class:

    class Base { ... };
    class Derived : public Base { ... };
    
    // then for the prototype
    void setRxHandler(void (Base::*h)(int)) { ... }
    // and you can use setRxHandler for all types that derive from Base, which gives you more control than the second option, which is:
    

    or use templates:

    template<typename T>
    void setRxHandler(void (T::*h)(int)) { ... }
    

    With the template option, you really have no control over what class will be used with setRxHandler (excluding RTTI), which can be exactly what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class Foo that has an Update() function, which I want
Let's say I have a class that has a member called data which is
For my exception class i have a constructor that has multi arguments (...) which
I have a class which has a DependencyProperty member: public class SomeClass : FrameworkElement
I have a class Application that my global.asax inherits from. The class has this
I have this class which has a double list template of a struct of
I have a class, lets say CAppPath which has a static method: public: static
Let's suppose we have a base class which has a virtual method: class BaseClass
I have a base class which has a method for moving files to appropriate
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();

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.