---
title: "Templates in C++"  
description: "In this blog, I’m explaining about templates in C++  Templates are also known as generic function or class which are used to implement a generic struc"  
author: "priyanka kushwaha"  
published: 2015-02-05  
updated: 2015-02-05  
canonical: https://www.mindstick.com/blog/754/templates-in-c-plus-plus  
category: ".net"  
tags: ["visual c++"]  
reading_time: 1 minute  

---

# Templates in C++

In this [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog), I’m explaining about [templates](https://www.mindstick.com/articles/12874/crucial-benefits-of-using-powerpoint-templates-in-your-business-presentations) in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)\

Templates are also [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) generic [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) or [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) which are used to implement a generic [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) for many structures of the same statements with different [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) types.

**There are two types of templates:**

1. Function [template](https://www.mindstick.com/blog/282/creating-custom-template-in-joomla)

2. Class template

##### Syntax

```
Template<Typename
T>                                                                                                                        Template<class T>
```

##### Feathers of templates:

1. A class generated from a class template is called a generate class.

\
2. A function generated from a function template is called a generate

\

function\
3. A [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) data member generated from a static data member template

\

is called a generated static data member.

##### Example:

```
 // TemplatesProgram.cpp : main project file. #include "stdafx.h"#include <iostream> using namespace std;using namespace System;template<typename T>class operation{public:void Add(T firstNum,T SecNum){            cout<<"Result"<<firstNum+SecNum;}}; int main(array<System::String ^> ^args){            operation<double> op;            double firstNum,secNum;            cout<<"Enter first Number";            cin>>firstNum;            cout<<"Enter second number";            cin>>secNum;            op.Add(firstNum,secNum);            Console::ReadKey(0);    return 0;}
```

---

Original Source: https://www.mindstick.com/blog/754/templates-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
