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
Copy file name to clipboardExpand all lines: docs/cpp/templates-and-name-resolution.md
+13-10Lines changed: 13 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@ translation.priority.ht:
31
31
- "zh-tw"
32
32
---
33
33
# Templates and Name Resolution
34
+
34
35
In template definitions, there are three types of names.
35
36
36
37
- Locally declared names, including the name of the template itself and any names declared inside the template definition.
@@ -45,52 +46,54 @@ In template definitions, there are three types of names.
45
46
46
47
- The template argument itself:
47
48
48
-
```
49
+
```cpp
49
50
T
50
51
```
51
52
52
53
- A qualified name with a qualification including a dependent type:
53
54
54
-
```
55
+
```cpp
55
56
T::myType
56
57
```
57
58
58
59
- A qualified name if the unqualified part identifies a dependent type:
59
60
60
-
```
61
+
```cpp
61
62
N::T
62
63
```
63
64
64
65
- A constorvolatile type for which the base type is a dependent type:
65
66
66
-
```
67
+
```cpp
67
68
const T
68
69
```
69
70
70
71
- A pointer, reference, array, or function pointer type based on a dependent type:
71
72
72
-
```
73
+
```cpp
73
74
T *, T &, T [10], T (*)()
74
75
```
75
76
76
77
- An array whose size is based on a template parameter:
77
78
78
-
```
79
+
```cpp
79
80
template <int arg> classX {
80
81
int x[arg] ; // dependent type
81
82
}
82
83
```
83
84
84
85
- a template type constructed from a template parameter:
85
86
86
-
```
87
+
```cpp
87
88
T<int>, MyTemplate<T>
88
89
```
89
90
90
-
## Type Dependence and Value Dependence
91
+
## Type Dependence and Value Dependence
92
+
91
93
Names and expressions dependent on a template parameter are categorized as type dependent or value dependent, depending on whether the template parameter is a type parameter or a value parameter. Also, any identifiers declared in a template with a type dependent on the template argument are considered value dependent, as is a integral or enumeration type initialized with a value-dependent expression.
92
94
93
95
Type-dependent and value-dependent expressions are expressions that involve variables that are type dependent or value dependent. These expressions can have semantics that differ, depending on the parameters used for the template.
0 commit comments