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

Conteúdo do Curso

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!

Tarefa

  • 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;

Tarefa

  • 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;

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 2. Capítulo 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!

Tarefa

  • 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;

Tarefa

  • 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;

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 2. Capítulo 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!

Tarefa

  • 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;

Tarefa

  • 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;

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

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!

Tarefa

  • 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;

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 2. Capítulo 1
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt