You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 99ef6b9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/cpp/partial-ordering-of-function-templates-cpp.md
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: "Partial Ordering of Function Templates (C++)"
2
+
title: "Partial ordering of function templates (C++)"
3
3
ms.date: "07/30/2019"
4
4
helpviewer_keywords: ["partial ordering of function templates"]
5
5
ms.assetid: 0c17347d-0e80-47ad-b5ac-046462d9dc73
6
6
---
7
-
# Partial Ordering of Function Templates (C++)
7
+
# Partial ordering of function templates (C++)
8
8
9
9
Multiple function templates that match the argument list of a function call can be available. C++ defines a partial ordering of function templates to specify which function should be called. The ordering is partial because there can be some templates that are considered equally specialized.
10
10
@@ -41,28 +41,32 @@ The following sample works as specified in the standard:
41
41
// compile with: /EHsc
42
42
#include<iostream>
43
43
44
-
template <classT> voidf(T) {
45
-
printf_s("Less specialized function called\n");
44
+
template <classT> voidf(T)
45
+
{
46
+
printf_s("Less specialized function called\n");
46
47
}
47
48
48
-
template <classT> void f(T*) {
49
-
printf_s("More specialized function called\n");
49
+
template <classT> void f(T*)
50
+
{
51
+
printf_s("More specialized function called\n");
50
52
}
51
53
52
-
template <classT> void f(const T*) {
53
-
printf_s("Even more specialized function for const T*\n");
54
+
template <classT> void f(const T*)
55
+
{
56
+
printf_s("Even more specialized function for const T*\n");
54
57
}
55
58
56
-
int main() {
57
-
int i =0;
58
-
const int j = 0;
59
-
int *pi = &i;
60
-
const int *cpi = &j;
61
-
62
-
f(i); // Calls less specialized function.
63
-
f(pi); // Calls more specialized function.
64
-
f(cpi); // Calls even more specialized function.
65
-
// Without partial ordering, these calls would be ambiguous.
59
+
int main()
60
+
{
61
+
int i =0;
62
+
const int j = 0;
63
+
int *pi = &i;
64
+
const int *cpi = &j;
65
+
66
+
f(i); // Calls less specialized function.
67
+
f(pi); // Calls more specialized function.
68
+
f(cpi); // Calls even more specialized function.
69
+
// Without partial ordering, these calls would be ambiguous.
66
70
}
67
71
```
68
72
@@ -76,4 +80,4 @@ Even more specialized function for const T*
0 commit comments