'Reference to Pointer'에 해당되는 글 1건

  1. 2010.01.26 Reference to Pointer

Reference to Pointer

CS/C/C++ 2010. 1. 26. 03:51
일단 간단한 예제는...
void set_p(int* p, int val)   { p = new int(val); }
void set_pr(int*& p, int val) { p = new int(val); }

int main(void)
{
    int *a;

    // set_p(a, 10);
    set_pr(a, 10);
    cout << *a << endl;    

    // ...

    return 0;
}

WebKit Code에서 사용된 예,
if (JSGlobalObject*& headObject = head()) {
        d()->prev = headObject;
        d()->next = headObject->d()->next;
        headObject->d()->next->d()->prev = this;
        headObject->d()->next = this;
} else {
        headObject = d()->next = d()->prev = this;
}
head()가 NULL인 경우 처리가 참 깔끔하게 된다...
: