Method for indirectly call pointers referred to

xiaoxiao2021-03-06  37

"Method of the class member referred to by indirect call pointer", list my code as follows: (Compilation platform Windows2003, Cygwin G 3.4.1, VC 2003)

Operatorexclass.h (file) ------ // about -> * Operator Example.

Class class {public: int fun (void);

INT m_var;

--------

Operatorexclass.cpp ------ // About -> * Operator Example.

#include #include "operatorexclass.h"

INT class :: fun (void) {std :: cout << "call function./n"; std :: cout << m_var << "/ n"; std :: cout << "end call / n";

Return 0;}

--------

Operatorex.cpp ------ // About -> * Operator Example.

#include "operatorexclass.h"

INT main (void) {class * pclass = new class (); int (Class :: * pfun) (void) = & class :: fun; // Note Braces Int (Class :: * PM_VAR) = & Class :: m_var;

(PCLASS -> * PM_VAR) = 321; (PCLASS -> * PFUN) ();

DELETE PCLASS; RETURN 0;

------ There is also a convenient skill: typedef int (Class :: * Pfun) (Void); PFUN PFUN = & Class :: fun;

转载请注明原文地址:https://www.9cbs.com/read-71450.html

New Post(0)