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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:57:39+00:00 2026-05-17T18:57:39+00:00

If you have this generic function: template<class type, class ret, class atype1, class atype2,

  • 0

If you have this generic function:

template<class type, class ret, class atype1, class atype2, class atype3>
ret call3(type *pClass, ret(type::* funcptr)(atype1, atype2, atype3), atype1 arg, atype2 arg2, atype3 arg3)
{
    //do some stuff here
    return (pClass->*funcptr)(arg, arg2, arg3);
}

and you do this:

class MyClass
{
  public: 
    void test(int, int, int){};
    void test(int, int){};
    void test(int, int, const char *){};  //comment this line, and it works fine.
};

...

    MyClass *a = new MyClass();
    call3(a, &MyClass::test, 1, 2, 3);

g++ will say:

no matching function for call to `call3(MyClass*&, <unknown type>, int, int, int)'

Is there any way to fix this?
(My code is probably very bad also since I’m not very good at C++.)

  • 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-17T18:57:39+00:00Added an answer on May 17, 2026 at 6:57 pm

    You can explicitly specify which template to use.

    call3<MyClass, void, int, int, int>( a, &MyClass::test, 1, 2, 3 );
    

    If you rearange the order of your template parameters, you can get the MyClass and void deduced from the argument, so the call when needing an overload will look like this:

    call3<int,int,int>( a, &MyClass::test, 1, 2, 3 )
    

    Note that when you dont actually need the explicit overload resolution it can still be

    call3( a, &MyClass::otherfunction, 1,2,3 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say you have simple template function (not class member for the sake of
I have a generic method with this (dummy) code (yes I'm aware IList has
This is probably my naivety showing through, but anyway... I have a generic interface
I have a dilemma. Suppose I have a template class: template <typename ValueT> class
This is a little contrived, but say I have a class interface like this:
I am trying to make a template class where there is a function that
No, this is not a question about generics. I have a Factory pattern with
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM

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.