How do you declare a const array of function pointers?

后端 未结 5 1033
忘了有多久
忘了有多久 2021-01-11 11:34

Firstly, I\'ve got functions like this.

void func1();
void func2();
void func3();

Then I create my typedef for the array:

v         


        
5条回答
  •  太阳男子
    2021-01-11 11:57

    Then I create my typedef for the array: void (*FP)();

    Did you miss typedef before void?

    Following works on my compiler.

     void func1(){}
     void func2(){}
     void func3(){}
    
     typedef void (*FP)();
    
    
     int main()
     {
         const FP ar[3]= {&func1, &func2, &func3};
     }
    

    EDIT

    (after seeing your edits)

    x.h

     class x;
     typedef void (x::*FP)(); // you made a mistake here
    
     class x
     {
       public:
          void func1();
          void func2();
          void func3();
          static const FP array[3];
     };
    

提交回复
热议问题