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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:33:21+00:00 2026-05-23T07:33:21+00:00

I referred to this somewhat similar question . However here the scenario is different:

  • 0

I referred to this somewhat similar question. However here the scenario is different:

struct A
{
  void foo (int i) {} // choice
  void foo (double i) {}
};

template<typename ObjType, typename FuncPtr>
void ReceiveFuncPtr (ObjType o, FuncPtr pf)
{
 (o.*pf)(1);
}

int main ()
{
  A obj;
  ReceiveFuncPtr(obj, &A::foo); // don't want typecast here
}

In the above test code, I have an overloaded foo inside A. Had there been only 1 foo then the code works fine. But for overloading case, compiler complains as:

error: no matching function for call
to `ReceiveFuncPtr(A&, [unresolved
overloaded function type])’

Instead of explicit typecasting while calling ReceiveFuncPtr(), is there any way that we can make some changes in its template parameter and enable it to receive foo(int) version always for any similar class A ?

Edit: Idea is not to worry about the type while calling the function. It should be as simple as, ReceiveFuncPtr(obj, &A::foo); And let the template do its work.

  • 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-23T07:33:21+00:00Added an answer on May 23, 2026 at 7:33 am

    how about this:

    template<typename ObjType>
    void ReceiveFuncPtr (ObjType o, void (ObjType::*pf)(int))
    {
     (o.*pf)(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Referred this question first. But seems my context is different. I'll try to be
i referred to this question and i've a similar problem JSF - Get the
I referred this on SO as the problem was similar to mine. In my
I have referred this question to learn how to post the checkbox selected values
My question is referred to this site I've been developing. See the place where
I have referred this for creating error message tool tips, to be displayed continuously
I have developed a resizable panel in GWT. For this i have referred the
I want parse xml by looping through it. I referred this but I am
I referred this siegmann android tutorial and successfully logged the Title , Author name
I referred to this post to make my hover work. But solution there is

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.