Skip to content

Commit dd71079

Browse files
author
Colin Robertson
committed
Fixes for feedback issues.
1 parent 66798ad commit dd71079

11 files changed

+371
-234
lines changed

docs/build/how-to-modify-the-target-framework-and-platform-toolset.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ translation.priority.mt:
3939
You can change [!INCLUDE[vcprvc](../build/includes/vcprvc_md.md)] project settings to target different versions of the .NET Framework and to use different platform toolsets. By default, the project system uses the .NET Framework version and the toolset version that correspond to the version of Visual Studio that you use to create the project. You can change the target platform toolset by modifying the project properties. You can change the target Framework by modifying the project (.vcxproj) file. You do not have to maintain a separate code base for every compilation target.
4040

4141
> [!IMPORTANT]
42-
> Some editions might not support modified target Frameworks or platform toolsets. For compatibility information, see [Porting, Migrating, and Upgrading Visual Studio Projects](/visualstudio/porting/porting-migrating-and-upgrading-visual-studio-projects).
42+
> Some editions might not support modified target Frameworks or platform toolsets. For compatibility information, see [Port, Migrate, and Upgrade Visual Studio Projects](/visualstudio/porting/port-migrate-and-upgrade-visual-studio-projects).
4343
4444
When you change the target Framework, also change the platform toolset to a version that supports that Framework. For example, to target the .NET Framework 4.5, you must use a compatible platform toolset such as Visual Studio 2015 (v140), Visual Studio 2013 (v120) or Visual Studio 2012 (v110). You can use the **Windows7.1SDK** platform toolset to target the .NET Framework 2.0, 3.0, 3.5, and 4, and the x86, Itanium, and x64 platforms.
4545

docs/cpp/special-member-functions.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ translation.priority.ht:
3939
---
4040
# Special member functions
4141

42-
The special member functions are class (or struct) member functions that, in certain cases, the compiler automatically generates for you. These functions are the [default constructor](constructors-cpp.md#default_constructors), the [destructor](destructors-cpp.md), the [copy constructor and copy assignment operator](copy-constructors-and-copy-assignment-operators-cpp.md), and the [move constructor and move assignment operator](move-constructors-and-move-assignment-operators-cpp.md). If your class does not define one or more of the special member functions, then the compiler may implicitly declare and define the functions that are used. The compiler does not generate functions if they are not needed.
42+
The *special member functions* are class (or struct) member functions that, in certain cases, the compiler automatically generates for you. These functions are the [default constructor](constructors-cpp.md#default_constructors), the [destructor](destructors-cpp.md), the [copy constructor and copy assignment operator](copy-constructors-and-copy-assignment-operators-cpp.md), and the [move constructor and move assignment operator](move-constructors-and-move-assignment-operators-cpp.md). If your class does not define one or more of the special member functions, then the compiler may implicitly declare and define the functions that are used. The compiler-generated implementations are called the *default* special member functions. The compiler does not generate functions if they are not needed.
4343

44-
The compiler does generates a default constructor only when you have not declared any other constructor. If you have declared only a constructor that takes parameters, code that attempts to call a default constructor causes the compiler to produce an error message. The compiler-generated default constructor performs simple member-wise [default initialization](initializers.md#default_initialization) of the object. Default initialization leaves all member variables in an indeterminate state.
44+
You can explicitly declare a default special member function by using the `= default` keyword. This causes the compiler to define the function only if needed, in the same way as if the function was not declared at all.
45+
46+
In some cases, the compiler may generate *deleted* special member functions, which are not defined and therefore not callable. This can happen in cases where a call to a particular special member function on a class doesn't make sense, given other properties of the class. To explicitly prevent automatic generation of a special member function, you can declare it as deleted by using the `= deleted` keyword.
47+
48+
The compiler generates a *default constructor*, a constructor that takes no arguments, only when you have not declared any other constructor. If you have declared only a constructor that takes parameters, code that attempts to call a default constructor causes the compiler to produce an error message. The compiler-generated default constructor performs simple member-wise [default initialization](initializers.md#default_initialization) of the object. Default initialization leaves all member variables in an indeterminate state.
4549

4650
The default destructor performs member-wise destruction of the object. It is virtual only if a base class destructor is virtual.
4751

4852
The default copy and move construction and assignment operations perform member-wise bit-pattern copies or moves of non-static data members. Move operations are only generated when no destructor or move or copy operations are declared. A default copy constructor is only generated when no copy constructor is declared. It is implicitly deleted if a move operation is declared. A default copy assignment operator is generated only when no copy assignment operator is explicitly declared. It is implicitly deleted if a move operation is declared.
4953

50-
You can explicitly declare a default special member function by using the `= default` keyword. This causes the compiler to define the function if needed, in the same way as if the function was not declared at all. To prevent automatic generation of a special member function, you can explicitly declare it as deleted by using the `= deleted` keyword.
51-
5254
## See Also
5355
[C++ Language Reference](cpp-language-reference.md)
5456

docs/error-messages/compiler-errors-1/compiler-error-c2065.md

+122-30
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,139 @@ translation.priority.ht:
3737
# Compiler Error C2065
3838
'identifier' : undeclared identifier
3939

40-
A variable's type must be specified in a declaration before it can be used. The parameters that a function uses must be specified in a declaration, or prototype, before the function can be used.
40+
The compiler can't find the declaration for an identifier. If the identifier is a variable, you must specify the type of the variable in a declaration before it can be used. If the identifier is a function name, the parameters that the function uses must be specified in a declaration before the function can be used. If the identifier is the tag for a user-defined type, for example, a `class` or `struct`, the type of the tag must be declared before it can be used. If the identifier is a type alias, the type must be declared by using a `using` declaration or `typedef` before the type can be used.
4141

42-
Possible causes:
42+
There are many possible causes for this error. Here are some of the most common issues:
4343

44-
1. Identifier name is misspelled.
44+
## Example: misspelled identifier
4545

46-
2. Identifier uses the wrong uppercase and lowercase letters.
46+
This error commonly occurs when the identifier name is misspelled, or the identifier uses the wrong uppercase and lowercase letters. The name in the declaration must exactly match the name you use.
4747

48-
3. Missing closing quote after a string constant.
49-
50-
4. You are compiling with a debug version of the C runtime, declaring a C++ Standard Library iterator variable in a `for` loop, and then trying to use that iterator variable outside the scope of the `for` loop. Compiling C++ Standard Library code with a debug version of the C runtime implies [/Zc:forScope](../../build/reference/zc-forscope-force-conformance-in-for-loop-scope.md). See [Debug Iterator Support](../../standard-library/debug-iterator-support.md) for more information.
48+
```cpp
49+
// C2065_spell.cpp
50+
// compile with: cl /EHsc C2065_spell.cpp
51+
#include <iostream>
52+
using namespace std;
53+
int main() {
54+
int someIdentifier = 42;
55+
cout << "Some Identifier: " << SomeIdentifier << endl;
56+
// C2065: 'SomeIdentifier': undeclared identifier
57+
// To fix, correct the spelling:
58+
// cout << "Some Identifier: " << someIdentifier << endl;
59+
}
60+
```
61+
62+
## Example: missing header file
63+
64+
You have not included the header file that declares the identifier. Make sure the file that contains the declaration for the identifier is included in every source file that uses it.
65+
66+
```cpp
67+
// C2065_header.cpp
68+
// compile with: cl /EHsc C2065_spell.cpp
69+
70+
//#include <stdio.h>
71+
int main() {
72+
fpos_t file_position = 42; // C2065: 'fpos_t': undeclared identifier
73+
// To fix, uncomment the #include <stdio.h> line
74+
// to include the header where fpos_t is defined
75+
}
76+
```
5177

52-
5. You may be calling a function in an SDK header file that is currently not supported in your build environment.
78+
You may see this error in Windows Desktop app source files if you define `VC_EXTRALEAN`, `WIN32_LEAN_AND_MEAN`, or `WIN32_EXTRA_LEAN`. These preprocessor macros exclude some header files from windows.h and afxv\_w32.h to speed compiles. Look in windows.h and afxv_w32.h for an up-to-date description of what's excluded.
5379

54-
6. Omitting necessary include files, especially if you define `VC_EXTRALEAN`, `WIN32_LEAN_AND_MEAN`, or `WIN32_EXTRA_LEAN`. These symbols exclude some header files from windows.h and afxv_w32.h to speed compiles. (Look in windows.h and afxv_w32.h for an up-to-date description of what's excluded.)
80+
## Eample: missing closing quote
5581

56-
7. Improper namespace scope. For example, to resolve C++ Standard Library functions and operators that are not fully qualified, you must specify the `std` namespace with the `using` directive. The following example fails to compile because the `using` directive is commented out and `cout` is defined in the `std` namespace:
82+
This error can occur if you are missing a closing quote after a string constant. This is an easy way to confuse the compiler.
5783

58-
## Example
59-
The following sample generates C2065 and shows how to fix it.
84+
```cpp
85+
// C2065_quote.cpp
86+
// compile with: cl /EHsc C2065_quote.cpp
87+
#include <iostream>
88+
89+
int main() {
90+
// Fix this issue by adding the closing quote to "Aaaa"
91+
char * first = "Aaaa, * last = "Zeee";
92+
std::cout << "Name: " << first
93+
<< " " << last << std::endl; // C2065: 'last': undeclared identifier
94+
}
95+
```
6096

97+
## Example: use iterator outside for loop scope
98+
99+
This error can occur if you declare an iterator variable in a `for` loop, and then you try to use that iterator variable outside the scope of the `for` loop. The compiler enables the [/Zc:forScope](../../build/reference/zc-forscope-force-conformance-in-for-loop-scope.md) compiler option by default. See [Debug Iterator Support](../../standard-library/debug-iterator-support.md) for more information.
100+
101+
```cpp
102+
// C2065_iter.cpp
103+
// compile with: cl /EHsc C2065_iter.cpp
104+
#include <iostream>
105+
#include <string>
106+
107+
int main() {
108+
// char last = '!';
109+
std::string letters{ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" };
110+
for (const char& c : letters) {
111+
if ('Q' == c) {
112+
std::cout << "Found Q!" << std::endl;
113+
}
114+
// last = c;
115+
}
116+
std::cout << "Last letter was " << c << std::endl; // C2065
117+
// Fix by using a variable declared in an outer scope.
118+
// Uncomment the lines that declare and use 'last' for an example.
119+
// std::cout << "Last letter was " << last << std::endl; // C2065
120+
}
61121
```
62-
// C2065.cpp
63-
// compile with: /EHsc
122+
123+
## Example: preprocessor removed declaration
124+
125+
This error can occur if you refer to a function or variable that is in conditionally compiled code that is not compiled for your current configuration. This can also occur if you call a function in a header file that is currently not supported in your build environment. If certain variables or functions are only available when a particular preprocessor macro is defined, make sure the code that calls those functions can only be compiled when the same preprocessor macro is defined. This issue is easy to spot in the IDE, because the declaration for the function is greyed out if the required preprocessor macros are not defined for the current build configuration.
126+
127+
This is an example of code that works when you build in Debug, but not Retail:
128+
129+
```cpp
130+
// C2065_defined.cpp
131+
// Compile with: cl /EHsc /W4 /MT C2065_defined.cpp
132+
#include <iostream>
133+
#include <crtdbg.h>
134+
#ifdef _DEBUG
135+
_CrtMemState oldstate;
136+
#endif
137+
int main() {
138+
_CrtMemDumpStatistics(&oldstate);
139+
std::cout << "Total count " << oldstate.lTotalCount; // C2065
140+
// Fix by guarding references the same way as the declaration:
141+
// #ifdef _DEBUG
142+
// std::cout << "Total count " << oldstate.lTotalCount;
143+
// #endif
144+
}
145+
```
146+
147+
## Example: use an unscoped identifier
148+
149+
This error can occur if your identifier is not properly scoped. For example, when C++ Standard Library functions and operators are not fully qualified by namespace, or you have not brought the `std` namespace into the current scope by using a `using` directive, the compiler can't find them. To fix this issue, you must either fully qualify the identifier names, or specify the namespace with the `using` directive.
150+
151+
This example fails to compile because `cout` and `endl` are defined in the `std` namespace:
152+
153+
```cpp
154+
// C2065_scope.cpp
155+
// compile with: cl /EHsc C2065_scope.cpp
64156
// using namespace std; // Uncomment this line to fix
65157
#include <iostream>
66158
int main() {
67-
cout << "Hello" << endl; // C2065
68-
69-
// Or try the following line instead
70-
std::cout << "Hello" << std::endl;
71-
}
159+
cout << "Hello" << endl; // C2065 'cout': undeclared identifier
160+
// C2065 'endl': undeclared identifier
161+
// Or try the following line instead
162+
std::cout << "Hello" << std::endl;
163+
}
72164
```
73165

74-
## Example
75-
When calling a generic function, if the intended type argument cannot be deduced from the parameters used, the compiler will report an error. For more information, see [Generic Functions (C++/CLI)](../../windows/generic-functions-cpp-cli.md).
166+
Identifiers that are declared inside of `class`, `struct`, or `enum class` types, must also be qualified by the name of the enclosing scope.
76167

77-
The following sample generates C2065 and shows how to fix it.
168+
## Example: C++/CLI type deduction failure
78169

79-
```
170+
This error can occur when calling a generic function, if the intended type argument cannot be deduced from the parameters used. For more information, see [Generic Functions (C++/CLI)](../../windows/generic-functions-cpp-cli.md).
171+
172+
```cpp
80173
// C2065_b.cpp
81174
// compile with: /clr
82175
generic <typename ItemType>
@@ -89,14 +182,13 @@ int main() {
89182
}
90183
```
91184
92-
## Example
93-
This error can also be generated as a result of compiler conformance work that was done for Visual C++ 2005: parameter checking for Visual C++ attributes.
185+
## Example: C++/CLI attribute parameters
94186
95-
The following sample generates C2065 and shows how to fix it.
187+
This error can also be generated as a result of compiler conformance work that was done for Visual C++ 2005: parameter checking for Visual C++ attributes.
96188
97-
```
98-
// C2065_c.cpp
99-
// compile with: /c
189+
```cpp
190+
// C2065_attributes.cpp
191+
// compile with: cl /c /clr C2065_attributes.cpp
100192
[module(DLL, name=MyLibrary)]; // C2065
101193
// try the following line instead
102194
// [module(dll, name="MyLibrary")];
@@ -105,4 +197,4 @@ int main() {
105197
struct MyStruct {
106198
int i;
107199
};
108-
```
200+
```

0 commit comments

Comments
 (0)