Struct a {<br/> int func () {return 0 ;}< br/> int val; <br/> }; <br/> struct B {<br/> int func () {return 0 ;}< br/> int val; <br/> }; <br/> struct c {<br/> static int A: * pval_a, B: * pval_ B; // pointer to the member variable (offset) <br/> static int (A: * pfunc_a) (), (B: * pfunc_ B) (); <br/>}; <br/> int :: * c: pval_a = & A: Val; <br/> int B: * C: pval_ B = & B: Val; <br/> int (:: * C: pfunc_a) () = & A: func; <br/> int (B: * C: pfunc_ B) () = & B: func;
By the way, a max function is implemented to compare the value of the data member of an object, without the need to overload operator <()
Template <typename _ object_type, typename _ member_type> <br/> inline _ object_type & test_max (<br/> _ object_type & A, <br/> _ object_type & B, <br/> _ member_type _ object_type: * member <br/>) {<br/> return. * Member> B. * Member? A: B; <br/>}
You do not need to write the template parameter list when using it.
... <Br/> A TA1, TA2; <br/> test_max (TA1, TA2, & A: Val); <br/>...