You asked:
Timer1 calls the function as follows:
Timer1.isrCallback();
How is that right?
Type Timer1.isrCallback - void (*)() . This is a pointer to a function. That is why you can use this syntax.
This is similar to using:
void foo() { } void test_foo() { void (*fptr)() = foo; fptr(); }
You can also use:
void test_foo() { void (*fptr)() = foo; (*fptr)(); }
but the first form is equally valid.
Update in response to OP comment
Given the published class definition that you would use:
(*Timer1.isrCallback)();
To use
(Timer1.*isrCallback)();
isrCallback must be defined as a non-member variable whose type is a pointer to a member variable in TimerOne .
void (TimerOne::*isrCallback)();
Example:
#include <iostream> class TimerOne { public: void foo() { std::cout << "In TimerOne::foo();\n"; } }; int main() { TimerOne Timer1; void (TimerOne::*isrCallback)() = &TimerOne::foo; (Timer1.*isrCallback)(); }
Exit:
In TimerOne::foo();
(Check this code)
If you want to define isrCallbak as a member variable in TimerOne , you will need to use:
#include <iostream> class TimerOne { public: void (TimerOne::*isrCallback)(); void foo() { std::cout << "In TimerOne::foo();\n"; } }; int main() { TimerOne Timer1; Timer1.isrCallback = &TimerOne::foo; // A little complicated syntax. (Timer1.*(Timer1.isrCallback))(); }
Output:
In TimerOne::foo();
(Check this code)
source share