Hi, I require help in understanding what's the purpose of the program below and what it does. I can't seem to understand what it is trying to do. There are some move semantics and all that but it is really hard for me to understand it since I am new to C++.. This program is related to the topic move semantics and r-value references.
I assume you can figure out that it's calculating fibonacci numbers, so your question is presumably about the & and && notation at the end of some member-function declarations. These are called "reference qualifiers".
The & at the end means that the implicit object is a lvalue reference.
The && means that the implicit object is an rvalue reference. (But *this is always an lvalue inside the function.)
Without & or && the implicit object is an lvalue reference that is allowed to bind to an rvalue.
So if the object that calculate is called on is a temporary object (as in TestRValue), then the && version will be called. Why the programmer thought it useful to clear the object's state is a mystery. I don't see the point. Normally that's something you would do when you move from an object, reseting its state to something reasonable after its guts have been ripped out.
BTW, the 10th fibonacci number is 55 not 89, so it gets the wrong answer.