Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Creating Your First Template | Creating First Template
C++ Templates
course content

Course Content

C++ Templates

C++ Templates

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

Creating Your First Template

Creating a template is actually quite simple, and it's one of the easiest parts of using them. To start, you'll need to create either a function or a class. We will start with the function.

cpp

main

copy
123456
void MyFirstTemplate() { } int main() { MyFirstTemplate(); }

As you can see, there is a very simple function that does nothing for now. We can easily call it inside the main function. Your task now is to turn it into a template.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 1. Chapter 2
toggle bottom row

Creating Your First Template

Creating a template is actually quite simple, and it's one of the easiest parts of using them. To start, you'll need to create either a function or a class. We will start with the function.

cpp

main

copy
123456
void MyFirstTemplate() { } int main() { MyFirstTemplate(); }

As you can see, there is a very simple function that does nothing for now. We can easily call it inside the main function. Your task now is to turn it into a template.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 1. Chapter 2
toggle bottom row

Creating Your First Template

Creating a template is actually quite simple, and it's one of the easiest parts of using them. To start, you'll need to create either a function or a class. We will start with the function.

cpp

main

copy
123456
void MyFirstTemplate() { } int main() { MyFirstTemplate(); }

As you can see, there is a very simple function that does nothing for now. We can easily call it inside the main function. Your task now is to turn it into a template.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Creating a template is actually quite simple, and it's one of the easiest parts of using them. To start, you'll need to create either a function or a class. We will start with the function.

cpp

main

copy
123456
void MyFirstTemplate() { } int main() { MyFirstTemplate(); }

As you can see, there is a very simple function that does nothing for now. We can easily call it inside the main function. Your task now is to turn it into a template.

Task

  • Follow the comments and turn the function into a template.

Once you've completed this task, click the button below the code to check your solution.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 2
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt