Skip to content

Commit 195c5fd

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#96 from Paul-Dempsey/patch-11
Use cpp for C++ code samples
2 parents 0ec45c6 + 2b24abd commit 195c5fd

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

docs/cpp/name-resolution-for-locally-declared-names.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ translation.priority.ht:
3131
- "zh-tw"
3232
---
3333
# Name Resolution for Locally Declared Names
34+
3435
The template's name itself can be referred to with or without the template arguments. In the scope of a class template, the name itself refers to the template. In the scope of a template specialization or partial specialization, the name alone refers to the specialization or partial specialization. Other specializations or partial specializations of the template can also be referenced, with the appropriate template arguments.
3536

36-
## Example
37+
## Example
38+
3739
The following code shows that the class template's name A is interpreted differently in the scope of a specialization or partial specialization.
3840

39-
```
41+
```cpp
4042
// template_name_resolution3.cpp
4143
// compile with: /c
4244
template <class T> class A {
@@ -54,12 +56,13 @@ template<> class A<int> {
5456
};
5557
```
5658
57-
## Example
59+
## Example
60+
5861
In the case of a name conflict between a template parameter and another object, the template parameter can or cannot be hidden. The following rules will help determine precedence.
5962
6063
The template parameter is in scope from the point where it first appears until the end of the class or function template. If the name appears again in the template argument list or in the list of base classes, it refers to the same type. In standard C++, no other name that is identical to the template parameter can be declared in the same scope. A Microsoft extension allows the template parameter to be redefined in the scope of the template. The following example shows using the template parameter in the base specification of a class template.
6164
62-
```
65+
```cpp
6366
// template_name_resolution4.cpp
6467
// compile with: /EHsc
6568
template <class T>
@@ -73,10 +76,11 @@ int main() {
7376
}
7477
```
7578

76-
## Example
79+
## Example
80+
7781
When defining a template's member functions outside the class template, a different template parameter name can be used. If the template member function definition uses a different name for the template parameter than the declaration does, and the name used in the definition conflicts with another member of the declaration, the member in the template declaration takes precedence.
7882

79-
```
83+
```cpp
8084
// template_name_resolution5.cpp
8185
// compile with: /EHsc
8286
#include <iostream>
@@ -107,10 +111,11 @@ int main() {
107111
Z::Z()
108112
```
109113

110-
## Example
114+
## Example
115+
111116
When defining a template function or member function outside the namespace in which the template was declared, the template argument takes precedence over the names of other members of the namespace.
112117

113-
```
118+
```cpp
114119
// template_name_resolution6.cpp
115120
// compile with: /EHsc
116121
#include <iostream>
@@ -140,10 +145,11 @@ int main() {
140145
C<T>::g
141146
```
142147

143-
## Example
148+
## Example
149+
144150
In definitions that are outside of the template class declaration, if a template class has a base class that does not depend on a template argument and if the base class or one of its members has the same name as a template argument, then the base class or member name hides the template argument.
145151

146-
```
152+
```cpp
147153
// template_name_resolution7.cpp
148154
// compile with: /EHsc
149155
#include <iostream>
@@ -177,5 +183,6 @@ Base
177183
1
178184
```
179185

180-
## See Also
181-
[Name Resolution](../cpp/templates-and-name-resolution.md)
186+
## See Also
187+
188+
[Name Resolution](../cpp/templates-and-name-resolution.md)

0 commit comments

Comments
 (0)