I have a class :
class X{
public :
void f ( int ) ;
int a ;
} ;
And the task is “Inside the code provide declarations for :
- pointer to int variable of class X
- pointer to function void(int) defined inside class X
- pointer to double variable of class X”
Ok so pointer to int a will be just int *x = &a, right ? If there is no double in X can I already create pointer to double inside this class ? And the biggest problem is the second task. How one declares pointer to function ?
These are called pointers to members. They are not regular pointers, i.e. not addresses, but “sort-of” offsets into an instance of the class (it gets a bit tricky with virtual functions.) So:
int X::*ptr_to_int_member;void (X::*ptr_to_member_func)( int );double X::*ptr_to_double_member;