How to call a pointer to a member function?

I am trying to do some testing with a pointer to a member function. What is wrong with this code? Statement bigCat.*pcat(); not compiled.

 class cat { public: void walk() { printf("cat is walking \n"); } }; int main(){ cat bigCat; void (cat::*pcat)(); pcat = &cat::walk; bigCat.*pcat(); } 
+49
c ++ function-pointers
Aug 30 '12 at 2:25
source share
1 answer

More parentheses required:

 (bigCat.*pcat)(); ^ ^ 

A function call ( () ) has a higher priority than the operator of binding a pointer to an element ( .* ). Unary operators have higher priority than binary operators.

+80
Aug 30 2018-12-12T00:
source share



All Articles