Conteúdo do Curso
C++ Templates
C++ Templates
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:
main
#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
toint
;
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
toint
;
Tudo estava claro?
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:
main
#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
toint
;
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
toint
;
Tudo estava claro?
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:
main
#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
toint
;
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
toint
;
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:
main
#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
toint
;