This question has already been answered:

Functions of this kind, which topic is c ++ where to find out? what to read? that's exactly when indicated in parentheses <int>.

Memory.Read<int>(0x76999A1); 

Reported as a duplicate by VTT , Twiss , Arsen , Kromster , Abyx c ++ Apr 11 '18 at 10:26 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

2 answers 2

Template function

The data type is indicated in the "triangular brackets" a great example is the sort of "bubble"

 template < class T > //T это тип передаваемых данных void bubbleSort (T* a, long size) { long i, j; T x; for (i = 0; i < size; i++) { for (j = size - 1; j > i; j--) { if (a[j - 1] > a[j]) { x = a[j - 1]; a[j - 1] = a[j]; a[j] = x; } } } } 

Called template functions like this:

 bubbleSort<int>(arr, 5); 

Where in triangular brackets we transfer data type.

All is clearly shown in the finished code.

 #include <iostream> using namespace std; template < class T > //T это тип передаваемых данных void bubbleSort (T* a, long size) { long i, j; T x; for (i = 0; i < size; i++) { for (j = size - 1; j > i; j--) { if (a[j - 1] > a[j]) { x = a[j - 1]; a[j - 1] = a[j]; a[j] = x; } } } } int main () { int arr[5] {1, 3, 2, 5, 4}; cout << "Non-sorted" << endl; for (int i = 0; i < 5; i++) { cout << arr[i] << endl; } bubbleSort<int>(arr, 5); // в треугольных скобках мы передаем тип данных int cout << "Sorted" << endl; for (int i = 0; i < 5; i++) { cout << arr[i] << endl; } return 0; } 

As a result, we get the following conclusion:

 Non-sorted 1 3 2 5 4 Sorted 1 2 3 4 5 
  • Will it be the same? bubbleSort (arr, 5) -> int; - Dmitry Mizantropovich
  • No in the triangular brackets we pass the data type of the array in our case int - ishidex2

This is a template function.

Below are links where you can read about them:

The first two links are a simple introduction, the third is an article on Wikipedia (useful, but a bit more complicated).

The last two - there is a lot of useful information, if you need to study more deeply, I strongly advise. (do not pay attention to the name, it has no purpose to offend anyone;))

Function Templates in C ++

Class Templates in C ++

Wikipedia: C ++ Templates

Programming C ++ Templates for idiots, part 1

Programming C ++ Templates for idiots, part 2

  • A collection of links without explanation is not the answer. - Kromster
  • Added an explanation. The question sounded like "where to read," so in the answer link. - zcorvid