Skip to content

Instantly share code, notes, and snippets.

@RalXYZ
Last active February 9, 2020 10:24
Show Gist options
  • Save RalXYZ/e7f6e895af4599b4f29afd318c8cdbfd to your computer and use it in GitHub Desktop.
Save RalXYZ/e7f6e895af4599b4f29afd318c8cdbfd to your computer and use it in GitHub Desktop.
Overload operators related to "plus"
// struct test already declared
const test test::operator++(int) {
test temp = *this;
this->a++;
return temp;
}
test& test::operator++() {
++this->a;
return *this;
}
test& test::operator+=(const test& temp) {
this->a += temp.a;
return *this;
}
test& test::operator+(const test& temp) const {
test sum;
sum.a = this->a + temp.a;
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment