Chapter 2. Building Original Templates

In This Chapter

  • Determining when to create a template

  • Understanding the elements of good template design

  • Developing a basic math template

  • Creating a structure template

  • Defining a class template

  • Using template specialization to your advantage

  • Building a library of templates

  • Using your custom built template libraries

C++ has been around for many years. Because of its longevity, C++ templates abound. In fact, it may seem that there is a template for every practical purpose. However, the templates that are available to the developer community through standardized and third-party resources usually reflect generalized needs. The individual company you work for or you as a developer may have specialized needs that a generalized template can't address.

Note

Every programming tool in existence offers a certain amount of flexibility. The reason why you see so many generalized tools is that someone developed them and the community as a whole decided to adopt them. Never think that you can't create your own tools. After all, someone created the generalized tools you work with daily — creating a custom tool requires nothing special, just time and thought on your part.

The trick to creating a customized tool is to think the process through, just as you would for any application you create. The fact that you'll use this customized tool to create multiple applications means that you must apply a higher standard than used for one-time applications to its design and the ...

Get C++ All-In-One For Dummies®, 2nd Edition 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.