Can some one explain how below program becomes infinte loop of "AabAabAab.."
Not really infinite. This will eventually crash your program because of stack overflow. This is what's going on. Here:
Base obj = Case();
You are creating a temporary object of type Case
and using it to initialize an object of type Base
.
The only way this can be done is by picking the user-defined conversion operator of Case
, which can return a Base
.
Now this conversion operator in turn happens to create a temporary object of type Case
, from which the return value of the operator should be initialized.:
return *(new Case);
Since the return value is itself of type Base
, the temporary now has to be converted to an object of type Base
- and since the temporary has type Case
, the same user-defined conversion operator is invoked again.
This is what attempts to generate an infinite recursion. Since each function call requires creating a stack frame, however, your neverending recursion will eventually cause a stack overflow, and your process will be terminated.