Trying overloading operator() in the following example:
#include <iostream>
using namespace std;
class Fib {
public:
Fib() : a0_(1), a1_(1) {}
int operator()();
private:
int a0_, a1_;
};
int Fib::operator()() {
int temp = a0_;
a0_ = a1_;
a1_ = temp + a0_;
return temp;
}
int main() {
Fib fib;
cout << fib() <<"," << fib() << "," << fib() << "," << fib() << "," << fib() << "," << fib() << endl;
}
It prints the fib sequence in the reverse order as 8,5,3,2,1,1. I understand the states are kept in () overlading but why the printing is showing up in the reverse order?