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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:42:18+00:00 2026-06-09T23:42:18+00:00

I am trying to transfer a function as a parameter to a different function.

  • 0

I am trying to transfer a function as a parameter to a different function.

for some reason it is not working.

//myClass.h
class MyClass
{
public:

typedef int (*MyClass::ptrToMember)(float, char);

  ptrToMember p1;
  MyClass::MyClass();
  void hello(ptrToMember fun);

  int SendIt (float a, char b); 

};



//MyClass.cpp
MyClass::MyClass(){
  p1 = &(MyClass::SendIt);
  hello(p1);

}
int MyClass::SendIt (float a, char b) 
{ 
  std::cout << "MyClass::SendIt "<<a<<std::endl; 

  return 1; 
}

void MyClass::hello(ptrToMember fun){

 int result = (*fun)(12, 'a');
  std::cout << result << std::endl;
}

would appreciate it, if someone can tell me what my mistake is.

  • 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-06-09T23:42:20+00:00Added an answer on June 9, 2026 at 11:42 pm
    typedef int (*MyClass::ptrToMember)(float, char);
                 ^
    // your mistake is here
    

    Pointers to class member functions are declared like this:

    typedef int (MyClass::*ptrToMember)(float, char);
                          ^
    

    And called like this (test is the class instance – can also be ‘this’):

     (test.*pointer)(parameters) // if test is automatically allocated
    

    or

     (test->*pointer)(parameters) // if test is a pointer
    

    The decleration operator is ::*, while the operator to invoke your pointer to a member function are .* and ->*.

    Edit:

    This line:

    p1 = &(MyClass::SendIt);
    

    actually has to be:

    p1 = &MyClass::SendIt; // without parentheses
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to model a transfer function block for say 1/(s+1). What is
I'm trying to transfer the contents of one list to another, but it's not
I'm trying to transfer some data from Access to SQL Server 2000 (there are
I'm trying to copy sql db between servers using Smo.Transfer class. And it's ok
I am trying to understand the Simulink (continuous) transfer function. In the documentation for
I'm trying to transfer the following URL validation function from my PHP code to
I'm trying to transfer some big streams (~1Mb) between DataSnap server/client but to no
i'm trying to make a form for my website, to transfer some data easily.
I'm trying to transfer a function across a network connection (using asyncore). Is there
I'm trying to use GET variables to transfer some simple data but for some

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.