Skip to content

Commit 564395c

Browse files
author
Paul Dempsey
authored
Apply cpp to code samples so they are syntax highlighted
- also consistent usage of bold/code
1 parent 8abe610 commit 564395c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/cpp/function-templates.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ translation.priority.ht:
3737
# Function Templates
3838
Class templates define a family of related classes that are based on the type arguments passed to the class upon instantiation. Function templates are similar to class templates but define a family of functions. With function templates, you can specify a set of functions that are based on the same code but act on different types or classes. The following function template swaps two items:
3939

40-
```
40+
```cpp
4141
// function_templates1.cpp
4242
template< class T > void MySwap( T& a, T& b ) {
4343
T c(a);
@@ -48,13 +48,13 @@ int main() {
4848
}
4949
```
5050
51-
This code defines a family of functions that swap the values of the arguments. From this template, you can generate functions that will swap `int` and **long** types and also user-defined types. `MySwap` will even swap classes if the class's copy constructor and assignment operator are properly defined.
51+
This code defines a family of functions that swap the values of the arguments. From this template, you can generate functions that will swap **int** and **long** types and also user-defined types. `MySwap` will even swap classes if the class's copy constructor and assignment operator are properly defined.
5252
5353
In addition, the function template will prevent you from swapping objects of different types, because the compiler knows the types of the `a` and `b` parameters at compile time.
5454
5555
Although this function could be performed by a nontemplated function, using void pointers, the template version is typesafe. Consider the following calls:
5656
57-
```
57+
```cpp
5858
int j = 10;
5959
int k = 18;
6060
CString Hello = "Hello, Windows!";
@@ -66,7 +66,7 @@ MySwap( j, Hello ); //error
6666

6767
Explicit specification of the template arguments for a function template is allowed. For example:
6868

69-
```
69+
```cpp
7070
// function_templates2.cpp
7171
template<class T> void f(T) {}
7272
int main(int j) {
@@ -75,10 +75,10 @@ int main(int j) {
7575
}
7676
```
7777
78-
When the template argument is explicitly specified, normal implicit conversions are done to convert the function argument to the type of the corresponding function template parameters. In the above example, the compiler will convert (`char j`) to type `int`.
78+
When the template argument is explicitly specified, normal implicit conversions are done to convert the function argument to the type of the corresponding function template parameters. In the above example, the compiler will convert `char j` to type `int`.
7979
8080
## See Also
8181
[Templates](../cpp/templates-cpp.md)
8282
[Function Template Instantiation](../cpp/function-template-instantiation.md)
8383
[Explicit Instantiation](../cpp/explicit-instantiation.md)
84-
[Explicit Specialization of Function Templates](../cpp/explicit-specialization-of-function-templates.md)
84+
[Explicit Specialization of Function Templates](../cpp/explicit-specialization-of-function-templates.md)

0 commit comments

Comments
 (0)