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