You get a bonus - 1 coin for daily activity. Now you have 1 coin

1.5.2. Indicators for component-functions

Lecture



You can define a pointer to component-functions.

value_type (class_name :: * pointer_name_function) (function_paragraph spec);

Example 1.5.2

// Determine pointer to member function of class

double (complex:: * ptcom) ();

// Setting the pointer

ptcom = & complex:: real;

// Now for object A

complex A (5.2,2.7);

// you can call its function

cout << (A. * ptcom) ();

// If the real method determines the type of reference

double & real (void) {return re;}

// then using this method you can change the re field

(A. * ptcom) () = 7.9;

// In this case, the pointer is defined as

double & (complex:: * ptcom) ();

You can also determine the type of function pointer

typedef double & (complex :: * PF) ();

and then determine the pointer itself

PF ptcom = & complex :: real;


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

C ++ (C plus plus)

Terms: C ++ (C plus plus)