Why can't static_cast a double void pointer?

后端 未结 5 1348
忘掉有多难
忘掉有多难 2021-01-12 06:05

Consider the following piece of code:

void **v_dptr(nullptr);
int  **i_dptr = static_cast(v_dptr);

The above example produces

5条回答
  •  太阳男子
    2021-01-12 07:00

    There are good answers for Q1, and the answer to Q2 depends a lot on the intention. If void **v_dptr is intended to be a pointer to a "generic" void* which you know is actually a int* and you want to cast accordingly, the following might be what you want:

    int *i_ptr = static_cast(*v_dptr);
    int **i_dptr = &i_ptr;
    

提交回复
热议问题