lvalue

1 view
Skip to first unread message

Arvind

unread,
May 10, 2005, 12:45:51 AM5/10/05
to CppF...@googlegroups.com
Hi All,

I have a question.

int i=9;
int *p = &(++i); // correct , doesn't give error.
//whereas
int *p = &(i++); // this gives an lvalue error.

WHY ????

Venkatesh Raja

unread,
May 10, 2005, 2:26:39 AM5/10/05
to CppF...@googlegroups.com
What compiler did u use to compile this ?
In my gcc compiler, both the statements gives error.

It may be compiler specific.

This may be tha alternative soln.
Assign the variable i to p (ie . p = &i) and do pointer arithmetic on p.
--

Regards,

Venkatesan P.R,
India.

------------------------------------------------------

namita thakker

unread,
May 10, 2005, 12:56:43 PM5/10/05
to CppF...@googlegroups.com
hi,
when you overload suffix operator u return this pointer that is
object pointer itself so first statement works
while
when you overload prefix operator you return by value that is u store
object current state in temporary variable then increment objects
value and return temp object value hence temp obj address cannot be
assigned to *p
i think this is the reason
bye
namita
Reply all
Reply to author
Forward
0 new messages