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

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

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