I'm new to programming and I have to Overload the += operator , + Operator and ++ post and prefix operator so the following operations work properly but I'm stuck.
Here is the number class:
#include <iostream>
class Number
{
private:
int m_value;
public:
Number(int value = 0);
std::ostream& print(std::ostream& ostr = std::cout)const;
};
std::ostream& operator<<(std::ostream& ostr, const Number& N);
using namespace std;
void prn(const Number& a, const Number& b, const Number& c)
{
cout << "c a b " << endl
<< c << " " << a << " " << b << endl;
cout << "--------------------" << endl;
}
int main()
{
Number a{ 10 }, b{ 20 }, c;
c = a + b;
prn(a, b, c);
c = ++a;
prn(a, b, c);
c = a += b;
prn(a, b, c);
c = b++;
prn(a, b, c);
return 0;
}
/// output:
/*
c a b
30 10 20
--------------------
c a b
11 11 20
--------------------
c a b
31 31 20
--------------------
c a b
20 31 21
----------------