Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does template<class key, class type> mean before a method in C++?

Tags:

People also ask

What is a template type?

Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.

Is template a keyword in C?

The keywords typename and template are now not required anymore if the qualifier is a member of the current instantiation.

Which keyword is used to define a class template?

class: A class keyword is used to specify a generic type in a template declaration.

What is template What is the need of template declare a template class?

Templates in c++ is defined as a blueprint or formula for creating a generic class or a function. To simply put, you can create a single function or single class to work with different data types using templates. C++ template is also known as generic functions or classes which is a very powerful feature in C++.


I have got this code and I am trying to understand the convention followed, all the method defined in the .cpp file have template<class KeyType, class DataType> written before them. What does that mean?

Example:

//Constructor
template<class key, class type>
MyOperation<key, type>::MyOperation()
{
  //method implementation
}

//A method
template<class key, class type>
MyOperation<key, type>::otherOperation()
{
  //method implementation
}

Thanks