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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:34:42+00:00 2026-06-01T18:34:42+00:00

How can I pass a class member function to a non-class member function’s parameter?

  • 0

How can I pass a class member function to a non-class member function’s parameter? I am getting the following compile error:

error: argument of type ‘void (MyNamespace::MyClass::)(int*)’ does not match ‘void (*)(int*)’

Library.h

typedef void (*testCallback)(int* iParam);
void UsingTheFoo(testCallback Callback);

Library.cpp

void UsingTheFoo(testCallback Callback)
{
  int *p_int = new int;
  *p_int = 5;
  Callback(p_int);
}

MyClass.cpp

namespace MyNamespace
{

    void MyClass::fooCB(int* a)
    {
        printf("hey! %d\n", *a);
    }


    void MyClass::testo()
    {
        UsingTheFoo(fooCB);
    }

} // MyNamespace

I can not change the code in “Library”, I need to use “UsingTheFoo” in MyClass member functions. I am aware my way is wrong, I searched and found similar questions but couldn’t understand (braindead at the end of shift 🙂 ) any of them completely to adapt for my problem.

I’ve already read: http://www.parashift.com/c++-faq-lite/pointers-to-members.html :S

  • 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-01T18:34:43+00:00Added an answer on June 1, 2026 at 6:34 pm

    Make method that you wanna to pass as a callback as static. You’ve got this error because all methods have implicitly first parameter – pointer to an object, this, so their prototype doesn’t correspond to callbacks’.

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

Sidebar

Related Questions

I am getting a compiler error when I try to pass a member function
Can I pass this to a function as a pointer, from within the class
How can I pass parameters to the OnSuccess function of the AjaxOptions class in
I have a class with a std::function constructor parameter. class ClazzA{ public: ClazzA(function<void()> foo){}
I am trying to pass a member function within a class to a function
I have to pass an argument of the type Pointer to a function from
You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
If I have a auto_ptr I can pass it for a reference?Like: auto_ptr<MyClass>Class(new MyClass);
What is the highest class in the hierarchy I can use to pass HttpSessionState
You can pass a function pointer, function object (or boost lambda) to std::sort to

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.