2.8. Pointers to Functions Add Flexibility

We must provide a function to return a vector of elements similar to fibon_seq() for each of our other five numerical sequences. The full set of functions might be declared as follows:

const vector<int> *fibon_seq( int size ); 
const vector<int> *lucas_seq( int size ); 
const vector<int> *pell_seq( int size ); 
const vector<int> *triang_seq( int size ); 
const vector<int> *square_seq( int size ); 
const vector<int> *pent_seq( int size ); 

What about fibon_elem()? Must we also provide six separate instances of this, one for each numeric sequence? The definition of fibon_elem() is as follows:

 bool fibon_elem( int pos, int &elem ) { const vector<int> *pseq = fibon_seq( pos ); if ( ! pseq ) { elem = 0; return ...

Get Essential C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.