I was overloaded the two operators: operator<< and operator++
operator<<
ArithmeticSequence & ArithmeticSequence::operator++()
{
this->lastElement += goToNext;
this->sum += lastElement;
return *this;
}
operator++
ostream & operator<<(ostream & out, const ArithmeticSequence as)
{
out << as.sum;
return out;
}
now the main is:
ArithmeticSequence AS(1.3, 2.5);
cout << "++AS sum: " << ++AS << " ++AS sum: " << ++AS << endl;
output:
++AS sum: 20.2 ++AS sum: 11.4
the correct output need to be:
++AS sum: 11.4 ++AS sum: 20.2
why the output is revers?