Skip to content

Commit 65e7a7b

Browse files
author
Colin Robertson
authored
Fix error message issues (MicrosoftDocs#89)
* Fix some broken links in compiler errors. * Fix _bittest syntax issue * Remove obsolete errors
1 parent ef43c6d commit 65e7a7b

File tree

58 files changed

+1395
-2093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1395
-2093
lines changed

docs/cpp/namespaces-cpp.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ translation.priority.ht:
3939
- "zh-tw"
4040
---
4141
# Namespaces (C++)
42-
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification. Identifiers outside the namespace can access the members by using the fully qualified name for each identifier, for example `std::vector<std::string> vec;`, or else by a [using Declaration](../cpp/using-declaration.md) for a single identifier (`using std::string`), or a [using Directive](../misc/using-directive-cpp.md) for all the identifiers in the namespace (`using namespace std;`). Code in header files should always use the fully qualified namespace name.
42+
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification. Identifiers outside the namespace can access the members by using the fully qualified name for each identifier, for example `std::vector<std::string> vec;`, or else by a [using Declaration](../cpp/using-declaration.md) for a single identifier (`using std::string`), or a [using Directive](../cpp/namespaces-cpp.md#using_directives) for all the identifiers in the namespace (`using namespace std;`). Code in header files should always use the fully qualified namespace name.
4343

4444
The following example shows a namespace declaration and three ways that code outside the namespace can accesses their members.
4545

46-
```
46+
```cpp
4747
namespace ContosoData
4848
{
4949
class ObjectManager
@@ -57,15 +57,15 @@ namespace ContosoData
5757

5858
Use the fully qualified name:
5959

60-
```
60+
```cpp
6161
ContosoData::ObjectManager mgr;
6262
mgr.DoSomething();
6363
ContosoData::Func(mgr);
6464
```
6565
6666
Use a using declaration to bring one identifier into scope:
6767
68-
```
68+
```cpp
6969
using WidgetsUnlimited::ObjectManager;
7070
ObjectManager mgr;
7171
mgr.DoSomething();
@@ -74,15 +74,15 @@ mgr.DoSomething();
7474

7575
Use a using directive to bring everything in the namespace into scope:
7676

77-
```
77+
```cpp
7878
using namespace WidgetsUnlimited;
7979
ObjectManager mgr;
8080
mgr.DoSomething();
8181
Func(mgr);
8282

8383
```
8484
85-
## using directives
85+
## <a id="using_directives"></a> using directives
8686
The `using` directive allows all the names in a **namespace** to be used without the *namespace-name* as an explicit qualifier. Use a using directive in an implementation file (i.e. *.cpp) if you are using several different identifiers in a namespace; if you are just using one or two identifiers, then consider a using declaration to only bring those identifiers into scope and not all the identifiers in the namespace. If a local variable has the same name as a namespace variable, the namespace variable is hidden. It is an error to have a namespace variable with the same name as a global variable.
8787
8888
> [!NOTE]
@@ -93,7 +93,7 @@ Func(mgr);
9393
## Declaring namespaces and namespace members
9494
Typically, you declare a namespace in a header file. If your function implementations are in a separate file, then qualify the function names, as in this example.
9595
96-
```
96+
```cpp
9797
//contosoData.h
9898
#pragma once
9999
namespace ContosoDataServer
@@ -106,7 +106,7 @@ namespace ContosoDataServer
106106

107107
Function implementations in contosodata.cpp should use the fully qualified name, even if you place a using directive at the top of the file:
108108

109-
```
109+
```cpp
110110
#include "contosodata.h"
111111
using namespace ContosoDataServer;
112112

@@ -123,7 +123,7 @@ int ContosoDataServer::Bar(){return 0;}
123123
124124
Members of a named namespace can be defined outside the namespace in which they are declared by explicit qualification of the name being defined. However, the definition must appear after the point of declaration in a namespace that encloses the declaration's namespace. For example:
125125
126-
```
126+
```cpp
127127
// defining_namespace_members.cpp
128128
// C2039 expected
129129
namespace V {
@@ -145,12 +145,12 @@ namespace V {
145145
If an identifier is not declared in an explicit namespace, it is part of the implicit global namespace. In general, try to avoid making declarations at global scope when possible, except for the entry point [main Function](../c-language/main-function-and-program-execution.md), which is required to be in the global namespace. To explicitly qualify a global identifier, use the scope resolution operator with no name, as in `::SomeFunction(x);`. This will differentiate the identifier from anything with the same name in any other namespace, and it will also help to make your code easier for others to understand.
146146

147147
## The std namespace
148-
All C++ standard library types and functions are declared in the std namespace or namespaces nested inside std.
148+
All C++ standard library types and functions are declared in the `std` namespace or namespaces nested inside `std`.
149149

150150
## Nested namespaces
151151
Namespaces may be nested. An ordinary nested namespace has unqualified access to its parent’s members, but the parent members do not have unqualified access to the nested namespace (unless it is declared as inline), as shown in the following example:
152152

153-
```
153+
```cpp
154154
namespace ContosoDataServer
155155
{
156156
void Foo();
@@ -172,7 +172,7 @@ namespace ContosoDataServer
172172
## Inline namespaces (C++ 11)
173173
In contrast to an ordinary nested namespace, members of an inline namespace are treated as members of the parent namespace. This characteristic enables argument dependent lookup on overloaded functions to work on functions that have overloads in a parent and a nested inline namespace. It also enables you to declare a specialization in a parent namespace for a template that is declared in the inline namespace. The following example shows how external code binds to the inline namespace by default:
174174

175-
```
175+
```cpp
176176
//Header.h
177177
#include <string>
178178

@@ -206,7 +206,7 @@ int main()
206206

207207
The following example shows how you can declare a specialization in a parent of a template that is declared in an inline namespace:
208208

209-
```
209+
```cpp
210210
namespace Parent
211211
{
212212
inline namespace new_ns
@@ -229,7 +229,7 @@ namespace Parent
229229

230230
The following example shows two versions of an interface, each in a nested namespace. The `v_20` namespace has some modification from the `v_10` interface and is marked as inline. Client code that uses the new library and calls `Contoso::Funcs::Add` will invoke the v_20 version. Code that attempts to call `Contoso::Funcs::Divide` will now get a compile time error. If they really need that function, they can still access the `v_10` version by explicitly calling `Contoso::v_10::Funcs::Divide`.
231231

232-
```
232+
```cpp
233233
namespace Contoso
234234
{
235235
namespace v_10
@@ -264,10 +264,10 @@ namespace Contoso
264264

265265
```
266266
267-
## Namespace aliases
267+
## <a id="namespace_aliases"></a> Namespace aliases
268268
Namespace names need to be unique, which means that often they should not be too short. If the length of a name makes code difficult to read, or is tedious to type in a header file where using directives can’t be used, then you can make a namespace alias which serves as an abbreviation for the actual name. For example:
269269
270-
```
270+
```cpp
271271
namespace a_very_long_namespace_name { class Foo {}; }
272272
namespace AVLNN = a_very_long_namespace_name;
273273
void Bar(AVLNN::Foo foo){ }
@@ -277,7 +277,7 @@ void Bar(AVLNN::Foo foo){ }
277277
## anonymous or unnamed namespaces
278278
You can create an explicit namespace but not give it a name:
279279

280-
```
280+
```cpp
281281
namespace
282282
{
283283
int MyFunc(){}
@@ -286,7 +286,5 @@ namespace
286286

287287
This is called an unnamed or anonymous namespace and it is useful when you want to make variable declarations invisible to code in other files (i.e. give them internal linkage) without having to create a named namespace. All code in the same file can see the identifiers in an unnamed namespace but the identifiers, along with the namespace itself, are not visible outside that file—or more precisely outside the translation unit.
288288

289-
## Remarks
290-
291289
## See Also
292-
[Declarations and Definitions](declarations-and-definitions-cpp.md)
290+
[Declarations and Definitions](declarations-and-definitions-cpp.md)

docs/cpp/new-and-delete-operators.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ C++ supports dynamic allocation and deallocation of objects using the [new](../c
4747

4848
For a list of the library files that comprise the C Runtime Library and the Standard C++ Library, see [CRT Library Features](../c-runtime-library/crt-library-features.md).
4949

50-
## The new operator
50+
## <a id="new_operator"> </a> The new operator
5151
When a statement such as the following is encountered in a program, it translates into a call to the function `operator new`:
5252

53-
```
53+
```cpp
5454
char *pch = new char[BUFFER_SIZE];
5555
```
5656

@@ -74,7 +74,7 @@ The two scopes for `operator new` functions are described in the following table
7474

7575
An **operator new** function defined for a class is a static member function (which cannot, therefore, be virtual) that hides the global **operator new** function for objects of that class type. Consider the case where **new** is used to allocate and set memory to a given value:
7676

77-
```
77+
```cpp
7878
// spec1_the_operator_new_function1.cpp
7979
#include <malloc.h>
8080
#include <memory.h>
@@ -104,15 +104,15 @@ int main()
104104

105105
The argument supplied in parentheses to **new** is passed to `Blanks::operator new` as the `chInit` argument. However, the global **operator new** function is hidden, causing code such as the following to generate an error:
106106

107-
```
107+
```cpp
108108
Blanks *SomeBlanks = new Blanks;
109109
```
110110

111111
In Visual C++ 5.0 and earlier, nonclass types and all arrays (regardless of whether they were of **class** type) allocated using the **new** operator always used the global **operator new** function.
112112

113113
Beginning with Visual C++ 5.0, the compiler supports member array **new** and **delete** operators in a class declaration. For example:
114114

115-
```
115+
```cpp
116116
// spec1_the_operator_new_function2.cpp
117117
class MyClass
118118
{
@@ -136,7 +136,7 @@ int main()
136136
### Handling insufficient memory
137137
Testing for failed memory allocation can be done with code such as the following:
138138

139-
```
139+
```cpp
140140
// insufficient_memory_conditions.cpp
141141
// compile with: /EHsc
142142
#include <iostream>
@@ -153,14 +153,14 @@ int main() {
153153
154154
There is another ways to handle failed memory allocation requests: write a custom recovery routine to handle such a failure, then register your function by calling the [_set_new_handler](../c-runtime-library/reference/set-new-handler.md) run-time function.
155155
156-
## The delete operator
156+
## <a id="delete_operator"> </a> The delete operator
157157
Memory that is dynamically allocated using the **new** operator can be freed using the **delete** operator. The delete operator calls the **operator delete** function, which frees memory back to the available pool. Using the **delete** operator also causes the class destructor (if there is one) to be called.
158158
159159
There are global and class-scoped **operator delete** functions. Only one **operator delete** function can be defined for a given class; if defined, it hides the global **operator delete** function. The global **operator delete** function is always called for arrays of any type.
160160
161161
The global **operator delete** function. Two forms exist for the global **operator delete** and class-member **operator delete** functions:
162162
163-
```
163+
```cpp
164164
void operator delete( void * );
165165
void operator delete( void *, size_t );
166166
```
@@ -173,7 +173,7 @@ void operator delete( void *, size_t );
173173

174174
The following example shows user-defined **operator new** and **operator delete** functions designed to log allocations and deallocations of memory:
175175

176-
```
176+
```cpp
177177
// spec1_the_operator_delete_function1.cpp
178178
// compile with: /EHsc
179179
// arguments: 3
@@ -226,7 +226,7 @@ int main( int argc, char *argv[] ) {
226226
227227
Beginning with Visual C++ 5.0, the compiler supports member array **new** and **delete** operators in a class declaration. For example:
228228
229-
```
229+
```cpp
230230
// spec1_the_operator_delete_function2.cpp
231231
// compile with: /c
232232
class X {

docs/cpp/sptr-uptr.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,14 @@ void MyFunction(char * __uptr __ptr32 myValue);
5656

5757
Use the `__sptr` and `__uptr` modifiers with pointer declarations. Use the modifiers in the position of a [pointer type qualifier](../c-language/pointer-declarations.md), which means the modifier must follow the asterisk. You cannot use the modifiers with [pointers to members](../cpp/pointers-to-members.md). The modifiers do not affect non-pointer declarations.
5858

59-
If you do not use the `__sptr` or `__uptr` modifier, and you enable [Compiler Warning (level 2) C4826](../error-messages/compiler-warnings/compiler-warning-level-2-c4826.md), the compiler issues a warning when a 32-bit pointer is converted to 64 bits.
60-
6159
## Example
6260
The following example declares 32-bit pointers that use the `__sptr` and `__uptr` modifiers, assigns each 32-bit pointer to a 64-bit pointer variable, and then displays the hexadecimal value of each 64-bit pointer. The example is compiled with the native 64-bit compiler and is executed on a 64-bit platform.
6361

64-
```
62+
```cpp
6563
// sptr_uptr.cpp
6664
// processor: x64
6765
#include "stdio.h"
6866

69-
// Warning C4826 is off by default.
70-
7167
int main()
7268
{
7369
void * __ptr64 p64;

docs/cpp/templates-cpp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int i = minimum(a, b);
7777

7878
The rules for how the compiler performs type deduction in function templates are based on the rules for ordinary functions. For more information, see [Overload Resolution of Function Template Calls](../cpp/overload-resolution-of-function-template-calls.md).
7979

80-
## Type parameters
80+
## <a id="type_parameters"></a> Type parameters
8181
In the `minimum` template above, note that the type parameter `T` is not qualified in any way until it is used in the function call parameters, where the const and reference qualifiers are added.
8282

8383
There is no practical limit to the number of type parameters. Separate multiple parameters by commas:
@@ -160,7 +160,7 @@ MyArray<MyClass*, 10> arr;
160160

161161
Other kinds of values including pointers and references can be passed in as non-type parameters. For example, you can pass in a pointer to a function or function object to customize some operation inside the template code.
162162

163-
## Templates as template parameters
163+
## <a id="template_parameters"></a> Templates as template parameters
164164
A template can be a template parameter. In this example, MyClass2 has two template parameters: a typename parameter `T` and a template parameter `Arr`:
165165

166166
```cpp

docs/cpp/unions.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ A `union` is a user-defined type in which all members share the same memory loca
4343

4444
## Syntax
4545

46-
```
46+
```cpp
4747
union [name] { member-list };
48-
4948
```
5049
5150
#### Parameters
@@ -60,7 +59,7 @@ union [name] { member-list };
6059
## Declaring a Union
6160
Begin the declaration of a union with the `union` keyword, and enclose the member list in curly braces:
6261
63-
```
62+
```cpp
6463
// declaring_a_union.cpp
6564
union RecordType // Declare a simple union type
6665
{
@@ -82,7 +81,7 @@ int main()
8281
## Using unions
8382
In the previous example, any code that accesses the union needs to know which member is holding the data. The most common solution to this problem is to enclose the union in a struct along with an additional enum member that indicates the type of the data currently being stored in the union. This is called a *discriminated union* and the following example shows the basic pattern.
8483

85-
```
84+
```cpp
8685

8786
#include "stdafx.h"
8887
#include <queue>
@@ -175,7 +174,7 @@ void Initialize()
175174
## Unrestricted Unions (C++11)
176175
In C++03 and earlier a union can contain non-static data members with class type as long as the type has no user provided constructors, destructors or assignment operators. In C++11, these restrictions are removed. If you include such a member in your union then the compiler will automatically mark any special member functions that are not user provided as deleted. If the union is an anonymous union inside a class or struct, then any special member functions of the class or struct that are not user provided are marked as deleted. The following example shows how to handle the case where one of the members of the union has a member that requires this special treatment:
177176
178-
```
177+
```cpp
179178
// for MyVariant
180179
#include <crtdbg.h>
181180
#include <new>
@@ -625,7 +624,7 @@ private:
625624
## Initializing unions
626625
You can declare and initialize a union in the same statement by assigning an expression enclosed in braces. The expression is evaluated and assigned to the first field of the union.
627626

628-
```
627+
```cpp
629628
#include <iostream>
630629
using namespace std;
631630

@@ -655,17 +654,16 @@ int main()
655654
![Storage of data in a numeric type union](../cpp/media/vc38ul1.png "vc38UL1")
656655
Storage of Data in NumericType Union
657656

658-
## Anonymous unions
657+
## <a id="anonymous_unions"> </a> Anonymous unions
659658
Anonymous unions are unions that are declared without a *class-name* or *declarator-list*.
660659

661-
```
662-
660+
```cpp
663661
union { member-list }
664662
```
665663
666-
Names declared in an anonymous union are used directly, like nonmember variables. Therefore, the names declared in an anonymous union must be unique in the surrounding scope.
664+
Names declared in an anonymous union are used directly, like nonmember variables. Therefore, the names declared in an anonymous union must be unique in the surrounding scope.
667665
668-
In addition to the restrictions for named unions, anonymous unions are subject to additional restrictions:
666+
In addition to the restrictions for named unions, anonymous unions are subject to these additional restrictions:
669667
670668
- They must also be declared as **static** if declared in file or namespace scope.
671669

docs/cpp/using-declaration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ using :: unqualified-id
5050
```
5151

5252
## Remarks
53-
The name becomes a synonym for an entity declared elsewhere. It allows an *individual* name from a specific namespace to be used without [explicit qualification](../misc/explicit-qualification.md). This is in contrast to the `using` directive, which allows *all* the names in a namespace to be used without qualification. See [using Directive](../misc/using-directive-cpp.md) for more information. This keyword is also used for [type aliases](../cpp/aliases-and-typedefs-cpp.md).
53+
The name becomes a synonym for an entity declared elsewhere. It allows an *individual* name from a specific namespace to be used without explicit qualification. This is in contrast to the `using` directive, which allows *all* the names in a namespace to be used without qualification. See [using directives](../cpp/namespaces-cpp.md#using_directives) for more information. This keyword is also used for [type aliases](../cpp/aliases-and-typedefs-cpp.md).
5454

5555
## Example
5656
A using declaration can be used in a class definition.

0 commit comments

Comments
 (0)