O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart by Brian Overland

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

12 Constructors: If You Build It…

One of the themes in this book is that object orientation is a way to create a fundamental new data type. I’ll focus on that idea for several chapters.

But I haven’t yet come through on this promise—that you can make classes as convenient as standard data types. One of the most convenient features of types such as int, float, double, and so on is that you can initialize them as you declare them. (C++ is somewhat more liberal than C in this regard; you can initialize with any value, not just constants.)

You’re about to see how easy it is to support initialization for objects, as well. Welcome to the craft of C++ construction.

Introducing Constructors

The term constructor is just C++-speak for an initialization ...

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