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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:35:35+00:00 2026-05-17T16:35:35+00:00

I know it sounds awefully confusing, I have a base template class which has

  • 0

I know it sounds awefully confusing, I have a base template class which has a function pointer, a child class(which is no longer a template class) needs to use that function pointer to point to a child class’s member function, and I get all kinds of errors.. Did I violate some universal law of C++?
here is the pseudo code:

template <class T>
class Base{
    public:
       typedef void (Base<T>::*fptr) (char in);
       void funcA(fptr FuncToCall){
                 FuncToCall('a');
       }
       ...
    };

class Child:public Base<char>{
   public: 
       void funcToCall(){...}
       void funcB(){
          funcA(funcToCall);
       }
}

Here is the error message I got:

error C2664: ‘Base< T >::funcA’ : cannot
convert parameter 1 from ‘void
(__thiscall Child::* )(char)’ to ‘void
(__thiscall Base< T >::* )(char)’

  • 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-17T16:35:36+00:00Added an answer on May 17, 2026 at 4:35 pm

    Your code is invalid.

    Firstly, in C++ to create a pointer to a member function you always have to use operator & and a qualified-name of the member, which means that your call to funcA should look as follows

    funcA(&Child::funcToCall); // close, but not yet, see "secondly" 
    

    Secondly, member pointers are contravariant. If want to initialize a base-member pointer object with a derived-member pointer value, you have to use an explicit static_cast

    funcA(static_cast<fptr>(&Child::funcToCall));
    

    Note that this is a valid, but potentially unsafe conversion, since it is now your responsibility to ensure that the actual object used on the left-hand side of the call (see “thirdly”) has that member.

    Thirdly, in order to call a function through such a pointer, you have to supply a concrete object on the left-hand side, so the call in funcA should look as follows (I assume that you want to call it for *this object)

    (this->*FuncToCall)('a');
    

    Fourthly, your funcToCall is supposed to have a parameter. Where is it?

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

Sidebar

Related Questions

I know this sounds backwards, but I have to convert this from C# to
I know this sounds rediculously easy but there is simply no documentation about this
Is the following code legal in C++. Accessing a friend class member public method?
I have a weird issue when committing changes in NHibernate. It doesn't throw an
Basically, I have an array, let's say @badvalues . I have another array, let's
I have two INSERT commands, that are useless to me like that because the
While working on a vb.net application, in which exceptions were handled poorly. It was
I have a rather (for me) complicated task with jQuery. I want to scan
Is it possible to run an SQL (Zend_Db_Select) query against a Zend_Db_Table_Row object? What
I got a problem with a system running on ASP.NET 1.1. It's a topic

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.