Why is *(ptra + 0).prop not valid and (*(ptra + 0)).prop valid ? . I know that left side of the dot operator must have a structure. But I am still confused. Could someone explain to me the difference between the two ?
class myobj
{
public:
int v;
};
int main()
{
myobj *ptra = new myobj[2]();
*(ptra + 0).v = 12 //Error
(*(ptra + 0)).v = 12 ; //OK
return 0;
}
Because
operator .has a higher precedence thenoperator *, someans
and not
*((ptr + 0).v)here is incorrect syntax, because(ptr + 0)is not a class or union, so has no any members.