现在的位置: 首页 > 综合 > 正文

C++指针释疑

2013年10月12日 ⁄ 综合 ⁄ 共 341字 ⁄ 字号 评论关闭

来源:<The C++ Programming Language >

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
}

抱歉!评论已关闭.