ITeye博客

C++指针释疑

mmdev · 2004-08-07 09:34 · Markdown

来源:<The C++ Programming Language<the language="" programming c>></the>

void f(int* pi)
{
void* pv = pi; // ok: implicit conversion
*pv; // error: can't dereference void*
pv++; // error: the size of the object pointed to is unknown
int* pi2 = static_cast<int*>(pv); // explicit conversion back to int*
double* pd1 = pv; // error
double* pd2 = pi; // error
double* pd3 = static_cast<double*>(pv); // ok but unsafe
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。