c++ - Function pointer to member function -


I want to set the function pointer as a member of a class which is an indicator in another function class. I am complaining because of this.

In this example, I output "1"); Int (* x) (); } Int A :: f () {Return 1; } Int main () {A one; A.x = a.f; Printf ("% d \ n", a.x ())}

but it fails in compiling. Why?

Syntax is incorrect A member pointer is a different type of category from the general indicator. The member pointer must experiment with the object of its class:

  class A {public: int f (); Int (A: * x) (); // & lt; - By declaring that this is an indicator for which class; Int A :: f () {Return 1; } Int main () {A one; A.x = & amp; A :: F; // Use: syntax printf ("% d \ n", (a. * (A.x)) ()); // Use the code together with one object of its class}  

The function is called on which object it just says that the object A . one at any time . Preparing as the left operator for the operator. The compiler will be told the caller object on that option.


Comments

Popular posts from this blog

bytearray - Removing trailing nulls from byte array in C# -

linux - Authenticating GTK app to run with root permissions -

WPF TextBlock Overflow Text to the Left -