I implemented ++ for a simple class and got 17. class A { public : int val; A(int v):val(v){} int operator++() { cout <<"empty arg called\n"; return ++val; } int operator++(int x) { cout <<x<<":arged arg called\n"; return val++; } }; ------------------ A b(4); cout <<++a + ++a +a++<<endl; ------------ 17 but story is different for your sample. let me tell the fact with a simpler problem : int b=4; cout << ++b + ++b ; will print 12 instead of 11! amazing huh ? what happens from right to left is : in the right statement : b becomes 5: in the left statement : b becomes 6 ( now be is 6 in both sides !) so right_b + left_b = 6+6 = 12
Regards On Tue, May 29, 2012 at 11:43 PM, Prateek Jain <prateek10011...@gmail.com>wrote: > how is it 6? > ++a(5) + ++a(6) + a++(6) it shud be 17 > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.