[WEBINAR] Application Acceleration: Faster Performance for End Users


Definition - What does Template mean?

A template is a C++ programming feature that permits function and class operations with generic types, which allows functionality with different data types without rewriting entire code blocks for each type.

Templates are a valuable utility in C++, especially when used with operator overloading and multiple inheritance. Templates reduce the effort associated with coding different data types to a single set of code and reduce debugging efforts.

Techopedia explains Template

C++ provides the following two types of templates used to implement general constructs, such as lists, queues, vectors and stacks:

  • Class template: Resembles a regular class definition but is prefixed by the following: template <class typename="" identifier="">, followed by the class body declaration, including member data and functions. Class template member function declarations and definitions are in the same header file. C++ class templates are best suited to container classes.
  • Function template: Implemented through template parameters, which is a special parameter type used to pass a type as a function argument. Thus, functionality may be adapted to more than one type or class without repeating the entire code. The format to declare a function template with a type parameter is either template <class identifier> function_declaration or template <typename identifier> function_declaration. There is no difference between the class and typename keywords.
Templates generally require type-checking at compile-time.

Template-generated code may be overriden by providing special definitions for specific types, which is known as template specialization. A special version of a function for a given set of template arguments is known as explicit specialization. A class template specialized by a subset of its parameters is known as a partial template specialization. Full specialization occurs f every parameter is specialized.

This definition was written in the context of C++

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.