Home > Mobile >  c pointer to member functions inside the same class
c pointer to member functions inside the same class

Time:11-13

I have the following:

class A {
     typedef void(A::*Exec)(); //this is for creating a pointer to a void the recives void
     void Method(Exec exec)    //Here i have 1 void that recives void parameter
     {
          exec();  
     }
     void SingleProcedure()
     {
          /* code here */
     }
public:
     void Init()
     {
         //Call void method indirectly
         Method(&A::SingleProcedure()); 
         //I don't know how to do the above thing
     }
}

So, shortly speaking. I need to have a lot of "void funct()" methods called in the same class by methods. How do i call a method pointer inside the same class?

CodePudding user response:

Ok, the working example, just don't want to send the OP to read books.

class A {
     typedef void(A::*Exec)(); //this is for creating a pointer to a void the recives void
     void Method(Exec exec)    //Here i have 1 void that recives void parameter
     {
          (this->*exec)();  
     }
     void SingleProcedure()
     {
          /* code here */
     }
public:
     void Init()
     {
         //Call void method indirectly
         Method(&A::SingleProcedure); 
         //I don't know how to do the above thing
     }
};
  • Related