Working with Multiple Typenames in Templates
Sometimes you will need more than one type to use in the function, and for this you can simply add more template parameters. Just make sure you give them different names.
Note
There is no inherent limit to the number of template parameters. However, as a general guideline keep the number of them as low as possible.
Create the function template print_pair
that allows you to output a formatted message containing a pair of values. By defining the template parameters, you can specify the types of the two values you want to print.
Swipe to start coding
Create and call a template with multiple type parameters.
- Fill in the
___
to complete the template definition. - Call the template twice:
- First call: Use
<int, std::string>
as the template types. - Second call: Use
<char, float>
as the template types.
- First call: Use
Solution
solution.cpp
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 5.88Awesome!
Completion rate improved to 5.88
Working with Multiple Typenames in Templates
Sometimes you will need more than one type to use in the function, and for this you can simply add more template parameters. Just make sure you give them different names.
Note
There is no inherent limit to the number of template parameters. However, as a general guideline keep the number of them as low as possible.
Create the function template print_pair
that allows you to output a formatted message containing a pair of values. By defining the template parameters, you can specify the types of the two values you want to print.
Swipe to start coding
Create and call a template with multiple type parameters.
- Fill in the
___
to complete the template definition. - Call the template twice:
- First call: Use
<int, std::string>
as the template types. - Second call: Use
<char, float>
as the template types.
- First call: Use
Solution
solution.cpp
Thanks for your feedback!
single
Awesome!
Completion rate improved to 5.88
Working with Multiple Typenames in Templates
Swipe to show menu
Sometimes you will need more than one type to use in the function, and for this you can simply add more template parameters. Just make sure you give them different names.
Note
There is no inherent limit to the number of template parameters. However, as a general guideline keep the number of them as low as possible.
Create the function template print_pair
that allows you to output a formatted message containing a pair of values. By defining the template parameters, you can specify the types of the two values you want to print.
Swipe to start coding
Create and call a template with multiple type parameters.
- Fill in the
___
to complete the template definition. - Call the template twice:
- First call: Use
<int, std::string>
as the template types. - Second call: Use
<char, float>
as the template types.
- First call: Use
Solution
solution.cpp
Thanks for your feedback!