[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

i = i++



hi
what should the outcome of this program be ?

void main()
{
    int i = 1 ;
    i = i++ ;
    cout<<i ;
}

i got the oputput as 2. but the following program gave
me 1

class A
{
    int num ;
    public :
	A(int n) : num(n) {}
	A & operator = (const A & rhs)
	{num = rhs.num ; return *this ;}	
	A operator ++(int)
	{A temp(num) ; num = num + 1 ; return temp ;}
	operator int()
	{return num ;}
} ;

void main()
{
    A a(1) ;
    a = a++ ;
    cout<<a ;
}

the result is the same on g++ and vc. i dont
understand. please help.
sindhoor

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/