更新时间:2022-02-04 00:50:30
&buf
是一个 const uint8_t **
.您真正想要做的是将 buf
传递给 serverAnswer
,您需要一个 const_cast
以允许从 const进行转换code> 指向
void*
的指针:
&buf
is a const uint8_t **
. What you actually want to do is pass buf
to serverAnswer
, you'll need a const_cast
to allow conversion from a const
pointer to void*
:
const uint8_t* buf;
serverAnswer(const_cast<uint8_t*>(buf), buf_len);
为了避免未定义的行为,您应该将 const
放回 serverAnswer
:
To avoid undefined behaviour you should put the const
back in serverAnswer
:
void serverAnswer(void *pUserData, int flag) {
const uint8_t* p = (const uint8_t *)pUserData;
uint8_t data = p[0];
}