CHAPTER 15

image

Introduction to Templates

Even for practical purposes, theory generally turns out the most important thing in the end.

—Oliver Wendell Holmes

In the previous chapter, we saw what you could do with C++/CLI generics. In this chapter, I will introduce templates, which are similar to generics in many ways and different in many others.

Comparison with Generics

Templates and generics both allow you to create functions and classes that implement functionality for multiple types. We can approach this in one of two ways:

  • Write code that is decoupled from the type of data that is being acted upon. The code only implements algorithms that ...

Get C++ 2013 for C# Developers,Second 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.