O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required