小编Alf*_*red的帖子

从 void* 到 void(*)(void*)[-fpermissive] 的无效转换

这个问题是关于线程提出的,但我有一个更简单的案例。(初学者)
我在不同的编译器中尝试了 C++ 的代码,但不起作用。
请告知如何替换该行: callback = (void*)myfunc;//-->error

typedef struct _MyMsg {
        int appId;
        char msgbody[32];
} MyMsg;    
void myfunc(MyMsg *msg)
{
        if (strlen(msg->msgbody) > 0 )
                printf("App Id = %d \n Msg = %s \n",msg->appId, msg->msgbody);
        else
                printf("App Id = %d \n Msg = No Msg\n",msg->appId);
}    
/*
 * Prototype declaration
 */
void (*callback)(void *);    
int main(void)
{
        MyMsg msg1;
        msg1.appId = 100;
        strcpy(msg1.msgbody, "This is a test\n");    
        /*
         * Assign the address of the function 'myfunc' …
Run Code Online (Sandbox Code Playgroud)

c c++ pointers function-pointers

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

c++ ×1

function-pointers ×1

pointers ×1