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

Contenido del 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!

Tarea

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

Tarea

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

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 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!

Tarea

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

Tarea

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

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 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!

Tarea

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

Tarea

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

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo 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!

Tarea

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

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 1
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt