-4

I want to store class member function address, to local data structure(table)

typedef struct
{
     unsigned int id; 
     void (TCLASS::*proc)();
} TSTRUCT;
class TCLASS{
  public:  
     void tfunct();  
     const  TSTRUCT t1 = { 1, &tfunct};
};
sonaj70
  • 1
  • 1
  • 5
    Was there a *question* ? Or were you wondering why `TCLASS` is an unknown type in your struct as you're missing a forward declaration, or why `&tfunct` should be `&TCLASS::tfunct` in your declaration of `t1`? – WhozCraig Aug 26 '14 at 07:56
  • Bad class names contest ? – Quentin Aug 26 '14 at 08:10

1 Answers1

0

Though you didn't write a question, assuming you are facing bunch of compiler errors.

See below :

class TCLASS ; //forward declaration 

 struct TSTRUCT
{
     unsigned int id; 
     void (TCLASS::*proc)( );
    // // Use the TSTRUCT constructor
    TSTRUCT(int i, void (TCLASS::*fptr)( ) ): id(i), proc(fptr) 
    {
    }

} ;

class TCLASS{
  public:  
     void tfunct(); 
    TCLASS() : t1(1, &TCLASS::tfunct ) // initialize the const member
                    //~~~~~~~~~~~^ Use &TCLASS::tfunct instead of &tfunct
    {

    }
     const  TSTRUCT t1;
};
P0W
  • 46,614
  • 9
  • 72
  • 119