O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

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

Strengths and Weaknesses of Templates

Picking the data type or class that will be at the core of your program or class can be difficult.

For instance, the calculator used ints until it was revealed that there were arithmetic problems as a result of that choice. You might recall from Lesson 4, “Numeric Input,” that changing the calculator to use floats instead of ints forced modifications affecting almost every part of the code.

Changing the object-oriented calculator to use long double instead of float for greater accuracy would be no different: It would require changes in every class. And if you wanted to have an int calculator, a float calculator, and a long double calculator all at the same time, you might have to reimplement the classes used ...

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