4.11. Pointers to Class Member Functions

The classes supporting the Fibonacci, Pell, Lucas, Square, and Pentagonal sequences are identical to those of the Triangular class except for the algorithm to generate the element sequence. In Chapter 5 we organize these classes into an object-oriented class hierarchy. In this section, we implement a general sequence class, num_sequence, to support all six sequences in a single class object. Here is our main() program:

int main() 
{ 
    num_sequence ns; 
    const int pos = 8; 
    for ( int ix = 1; ix < num_sequence::num_of_sequences(); ++ix ) 
    { 
          ns.set_sequence( num_sequence::nstype( ix )); 
          int elem_val = ns.elem( pos ); 
          display( cout, ns, pos, elem_val ); 
    } 
} 

ns is our general sequence class object. With each iteration ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.