How do I overload the increment operator so that this code becomes invalid -
Point p(2, 3);
++++p;
while allowing the following -
Point p(2, 3), a(0, 0), b(1, 4);
a = ++p + b;
Like in C this would be invalid -
int a = 2;
++++a;
How do I overload the increment operator so that this code becomes invalid -
Point p(2, 3);
++++p;
while allowing the following -
Point p(2, 3), a(0, 0), b(1, 4);
a = ++p + b;
Like in C this would be invalid -
int a = 2;
++++a;
Copyright © 2021 Jogjafile Inc.
One way you could do this is to make your
operator++()return aconstreference. That would prevent subsequent modification of the returned value, as in a 'chained'++++p;.Here's an outline version that also includes the required binary addition operator, implemented as a non-member function (as is normal):