Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
The Purpose of Templates | Templates Usage
C++ Templates
course content

Зміст курсу

C++ Templates

C++ Templates

1. Creating First Template
2. Templates Usage
3. Template Specialization
4. Class
5. Template Metaprogramming

The Purpose of Templates

By this points you already have to know that templates can take a type as a parameter and we even can use it inside of it. Let's refresh our memory:

cpp

main

copy
12345678910111213
#include <iostream> // Specifying the template parameter // VVV template<typename T> void MyFirstTemplate() { // Using the template parameter // VVV std::cout << typeid(T).name() << std::endl; } int main() { MyFirstTemplate<void>(); }

And here hides the power of templates. If we can use the template parameter inside a template that means we can create a template function that can be used with any data type!

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

The Purpose of Templates

By this points you already have to know that templates can take a type as a parameter and we even can use it inside of it. Let's refresh our memory:

cpp

main

copy
12345678910111213
#include <iostream> // Specifying the template parameter // VVV template<typename T> void MyFirstTemplate() { // Using the template parameter // VVV std::cout << typeid(T).name() << std::endl; } int main() { MyFirstTemplate<void>(); }

And here hides the power of templates. If we can use the template parameter inside a template that means we can create a template function that can be used with any data type!

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

The Purpose of Templates

By this points you already have to know that templates can take a type as a parameter and we even can use it inside of it. Let's refresh our memory:

cpp

main

copy
12345678910111213
#include <iostream> // Specifying the template parameter // VVV template<typename T> void MyFirstTemplate() { // Using the template parameter // VVV std::cout << typeid(T).name() << std::endl; } int main() { MyFirstTemplate<void>(); }

And here hides the power of templates. If we can use the template parameter inside a template that means we can create a template function that can be used with any data type!

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

By this points you already have to know that templates can take a type as a parameter and we even can use it inside of it. Let's refresh our memory:

cpp

main

copy
12345678910111213
#include <iostream> // Specifying the template parameter // VVV template<typename T> void MyFirstTemplate() { // Using the template parameter // VVV std::cout << typeid(T).name() << std::endl; } int main() { MyFirstTemplate<void>(); }

And here hides the power of templates. If we can use the template parameter inside a template that means we can create a template function that can be used with any data type!

Завдання

  • Finish the creation of MainTemplatePurpose template;
  • Set the type of parameters of function as a template parameter (T);
  • Change the specified type for template from std::string to int;

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 1
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt