Dereferencing pointers

S

Sharad Kala

nifsmith said:
Is

*(pointer1->pointer2)

The same as

(*(*pointer1).pointer2)

Yes.
Section 5.2.5 paragraph 3 - "If E1 has the type ``pointer to class X,'' then
the expression E1->E2 is converted to the equivalent form (*(E1)).E2;"

Sharad
 
J

JKop

nifsmith posted:
Is

*(pointer1->pointer2)

The same as

(*(*pointer1).pointer2)

TYIA

nifsmith


Yes, it is for *pointers*.


Note however, that for acutal objects, it doesn't always hold true.


For instance:


struct Monkey
{
int* tail;
};


class Blah
{
public:

Monkey a;

Monkey b;

Monkey& operator*()
{
return a;
}

Monkey& operator->()
{
return b;
}
};


int main()
{
Blah poo;

int k;

*( poo->tai l) = &k;

*( (*poo).tail ) = &k;
}


In that above, the statements do two totally different things, ie. there's
two different "tail"s!

(Actually now as I'm writing this, I'm not 100% sure that you can overload
->)


-JKop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top