Not Yet Answered # overload functions

Dogtree 23

0

This might give you a start for how to define them:

```
#include <iostream>
#include <utility>
class Integer {
int _val;
public:
Integer(): _val(0) {}
Integer(int val): _val(val) {}
int get() const { return _val; }
Integer operator+=(const Integer& rhs) { return _val += rhs._val; }
Integer operator-=(const Integer& rhs) { return _val -= rhs._val; }
Integer operator*=(const Integer& rhs) { return _val *= rhs._val; }
Integer operator/=(const Integer& rhs) { return _val /= rhs._val; }
Integer operator%=(const Integer& rhs) { return _val %= rhs._val; }
Integer operator+(const Integer& rhs) { return _val + rhs._val; }
Integer operator-(const Integer& rhs) { return _val - rhs._val; }
Integer operator*(const Integer& rhs) { return _val * rhs._val; }
Integer operator/(const Integer& rhs) { return _val / rhs._val; }
Integer operator%(const Integer& rhs) { return _val % rhs._val; }
Integer operator++() { return *this += 1; }
Integer operator++(int) { Integer temp(*this); ++*this; return temp; }
Integer operator--() { return *this -= 1; }
Integer operator--(int) { Integer temp(*this); --*this; return temp; }
friend bool operator==(const Integer& lhs, const Integer& rhs)
{ return lhs._val == rhs._val; }
friend bool operator<(const Integer& lhs, const Integer& rhs)
{ return lhs._val < rhs._val; }
};
int main()
{
using namespace std::rel_ops; // Sneaky sneaky ;-)
Integer a(20);
// Op-assign operators
std::cout << a.get() <<'\n';
a += 2;
std::cout << a.get() <<'\n';
a -= 2;
std::cout << a.get() <<'\n';
a *= 2;
std::cout << a.get() <<'\n';
a /= 2;
std::cout << a.get() <<'\n';
a %= 2;
std::cout << a.get() <<'\n';
a = 20;
Integer c;
// Arithmetic operators
std::cout << c.get() <<'\n';
c = a + 2;
std::cout << c.get() <<'\n';
c = a - 2;
std::cout << c.get() <<'\n';
c = a * 2;
std::cout << c.get() <<'\n';
c = a / 2;
std::cout << c.get() <<'\n';
c = a % 2;
std::cout << c.get() <<'\n';
a = 20;
// Increment/decrement
std::cout << (++a).get() <<'\n';
std::cout << (a++).get() <<'\n';
std::cout << (--a).get() <<'\n';
std::cout << (a--).get() <<'\n';
a = 20;
c = 20;
// Relational operators
std::cout << (a == c) << '\n';
std::cout << (a != c) << '\n';
std::cout << (a < c) << '\n';
std::cout << (a <= c) << '\n';
std::cout << (a > c) << '\n';
std::cout << (a >= c) << '\n';
}
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

```
from turtle import *
import random
def allTriMedian (w=300):
speed (0)
vertices = []
point = turtle.Point(x,y)
for i in range (3):
x = random.randint(0,300)
y = random.randint(0,300)
vertices.append(trutle.Point(x,y))
point = turtle.Point(x,y)
triangle = turtle.Polygon(vertices)
a = triangle.side()
b = triangle.side()
c = triangle.side()
m1 = tirangle.median
m2 = triangle.median ...
```

Hi!

I have two tables, I will call them first-half and second-half (of the year)

```
Table: first
id jan feb mar apr
-----------------------
2 80 90 70 60
3 50 40 60 30
Table: second
id jan feb mar apr
-----------------------
2 50 70 60 90
3 80 60 50 ...
```

I'm trying to figure out how do i print a distinct enum value by using a conditional statement in my construction of array.

I have a enum declaration

`enum Animal {Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig};`

And i construct my array using a voidptr ...