4.2. What Are Class Constructors and the Class Destructor?

Each of our numeric sequences is a good candidate for a class. A numeric sequence class object represents a range of elements within its associated sequence. By default, the beginning position is 1. For example,

Fibonacci fib1( 7, 3 ); 

defines a Fibonacci class object of 7 elements beginning at position 3, and

Pell pel( 10 ); 

defines a Pell class object of 10 elements beginning at the default position of 1. Finally,

Fibonacci fib2( fib1 ); 

initializes fib2 to a copy of fib1.

Each class must keep track both of its length — how many elements of the series are represented — and of a beginning position. A 0 or negative beginning position or length is not permitted. We store both the ...

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.