Not so obvious pointers

I have a class:

class X{
 public :
 void f ( int ) ;
 int a ;
} ;

And the task: "Inside the code contains declarations for:

  • pointer to an int variable of class X
  • pointer to void (int) function defined inside class X
  • pointer to a double variable of class X "

So, a pointer to int a will be just int * x = & a, right? If there is no double in X, can I already create a double pointer inside this class? And the biggest problem is the second task. How to declare a pointer to a function?

+3
source share
3 answers

. , .. , "" ( .) :

  • int X::*ptr_to_int_member;
  • void (X::*ptr_to_member_func)( int );
  • double X::*ptr_to_double_member;
+3

. , , , .

this.

+1

"*" :

Franks_Class * p_franks_class; // Declares a pointer to an instance of Franks_Class.

:

typedef void (*My_Int_Function_Ptr)(int parameter);

() My_Int_Function_Ptr, , int void.

From this and good C ++ book, you can answer the rest of your questions.

0
source

Source: https://habr.com/ru/post/1738112/


All Articles