Calling a Function From a String With the Function’s Name in C++

前端 未结 8 1087
故里飘歌
故里飘歌 2020-12-10 15:35

How can I call a C++ function from a string?

Instead of doing this, call the method straight from string:

void callfunction(const char* callthis, int         


        
8条回答
  •  粉色の甜心
    2020-12-10 16:31

    Alternative: You could use array of function pointers and call the desired function using its index.

    typedef void (*TFunc)(int, int);
    
    TFunc arrptr[100];
    
    void callFunction(int index, int params[])
    {
        (*arrptr[index])(params[0], params[1]);
    }
    

提交回复
热议问题