Answers for "what is template in c++"

C++
0

what is template in c++

A template is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we don’t need to write the same code for different data types. For example, a software company may need sort() for different data types. Rather than writing and maintaining the multiple codes, we can write one sort() and pass data type as a parameter. 
C++ adds two new keywords to support templates: ‘template’ and ‘typename’. The second keyword can always be replaced by keyword ‘class’.
Posted by: Guest on November-22-2021
0

templates of templates c++

namespace std {
  template<typename t> struct hash<MyClass<t>>
  {
  	size_t operator() (const MyClass<t>& c) const;
  }
}

// You can also do things like

template<template<typename t> class type> func_name<type<t>>();
Posted by: Guest on May-14-2020

Browse Popular Code Answers by Language