How do you declare a const array of function pointers?

后端 未结 5 1053
忘了有多久
忘了有多久 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:50

    Which compiler are you using? This works on VS2005.

    #include 
    
    void func1() {std::cout << "func1" << std::endl;}
    void func2() {std::cout << "func2" << std::endl;}
    void func3() {std::cout << "func3" << std::endl;}
    
    int main()
    {
    int ret = 0;
    
    typedef void (*FP)();
    
    const FP array[3] = {&func1, &func2, &func3};
    
    return ret;
    }
    

提交回复
热议问题