Object Oriented Approach to Display a sequence of numbers without any For-Loop or Recursion
Suppose we have to display a sequence of numbers like from 10 to 20 i.e.
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
without using any for-loop and recursion.
We will use two concepts here,
- Static Variable
Create a Structure with a static member variable i.e. a Counter. Then in this structure’s constructor display the Counter and increment it.
static int mCounter;
int NumberGenerator::mCounter = 10;
Now in the main function just Create 11 Objects of this Structure and hence constructor will be called 10 times.
Inside each constructor call, a static counter will be printed and its value will be incremented.
Thus a sequence of integers will be printed.
- Best Python Tutorials on lists, dict, functions, iterators & many more.
- Data Analysis in Python using Pandas Dataframe - Top Tutorials
C++11 / C++14 Resources
- Best C++11 Tutorials on Topics like Smart Pointers, tuples, Unordered map / set, lambda function etc.
- C++11 Multi-threading Series
- C++ - Boost Library Tutorials