Quantcast
Channel: How can I pass a member function where a free function is expected? - Stack Overflow
Viewing all articles
Browse latest Browse all 10

How can I pass a member function where a free function is expected?

$
0
0

The question is the following: consider this piece of code:

#include <iostream>class aClass{public:    void aTest(int a, int b)    {        printf("%d + %d = %d", a, b, a + b);    }};void function1(void (*function)(int, int)){    function(1, 1);}void test(int a,int b){    printf("%d - %d = %d", a , b , a - b);}int main(){    aClass a;    function1(&test);    function1(&aClass::aTest); // <-- How should I point to a's aClass::test function?}

How can I use the a's aClass::test as an argument to function1? I would like to access a member of the class.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images