









































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










































int x = 1, y = 2; cout << y++ << endl; cout << y;
int y = 2; y++++; // Error
y++ = x; // Error
Post-increment ++ returns by value, hence an error while assignment
int y = 2; cout << ++y << endl; cout << y << endl;
int x = 2, y = 2; ++++y; cout << y; ++y = x; cout << y;
4 2
Pre-increment ++ returns by reference, hence NOT an error
Complex & Complex::operator++(){
real = real + 1;
return * this;
}
Complex & operator ++ (Complex & h){
h.real += 1;
return h;
}
whether it is a pre-increment
or a post-increment?
Member function with 1 dummy int argument
OR
Non-member function with two arguments
class Complex{
...
Complex operator ++ (int);
// friend Complex operator // ++(const Complex &, int);
}
Complex Complex::operator ++ (int){
*complex t = this;
real += 1;
return t;
}
Complex h1, h2, h3;
h1++;
h3++ = h2 + h3++; // Error…
operator -- is implemented in
exactly the same way