From the course: C Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Understanding templates

Understanding templates - C Tutorial

From the course: C Essential Training

Understanding templates

- [Instructor] C templates are wonderfully simple and powerful. This is the C feature that supports generic programming. Generic programming refers to code that works independent of type. While C is a strongly typed language, there's still great benefit in being able to write functions and classes that are type agnostic, that is they operate on objects of various types. Because C supports defining your own types through classes and operator overloads, it's possible to do a great deal of generic programming in templates while leaving implementation details to the classes and operators. Template declarations look just like normal function or class declarations with one distinction. They're proceeded by the template keyword and a set of type identifiers. These type identifiers are used as placeholders by the template code to be replaced during compilation with actual types. When a function or class is used from…

Contents