C2065
Visual C++ Programming Language
Severity: MinorWhat Does This Error Mean?
C2065 means the compiler encountered an identifier — a variable, function, class, or enum name — that it has not seen a declaration for. The program will not compile until the identifier is declared or the correct header is included. The error message names the identifier: C2065: 'identifier': undeclared identifier.
Affected Models
- Visual Studio 2015–2022
- MSVC v14.x / v17.x
- Visual C++ command-line compiler (cl.exe)
Common Causes
- A required #include header is missing — the class or function is declared in a header you have not included
- A typo in the identifier name — C++ is case-sensitive, so myVar and myvar are different
- Using a variable or function before it is declared in the file
- Missing 'using namespace' or fully-qualified name (e.g. std::string instead of string)
- The identifier is inside an #ifdef block that is not active for the current build configuration
How to Fix It
-
Read the error message — it tells you exactly which identifier was not found. Search your code for that name and check its spelling.
C2065 pinpoints the location (file, line, column). In Visual Studio, double-clicking the error in the Error List jumps to the exact line.
-
Check that the required header is included at the top of the file. For standard library types, look up which header defines them.
Examples: std::string needs <string>, std::vector needs <vector>, printf needs <cstdio>. If you are using a third-party library, include its header file.
-
Check for a missing 'using namespace std;' or switch to fully-qualified names such as std::cout instead of cout.
Without 'using namespace std;', all standard library names must be prefixed with 'std::'. Using fully-qualified names is the recommended practice in header files.
-
Make sure any variable or function is declared before the line where it is used. Move declarations to the top of the scope or add a forward declaration.
C++ requires that a name be declared before it is used in the same translation unit. If function A calls function B and B is defined after A, add a forward declaration of B before A.
Frequently Asked Questions
Why does C2065 point to the wrong line?
C2065 fires at the point where the compiler first tries to use the undeclared name. The actual mistake (missing #include or typo in a declaration) is often on a different, earlier line. Fix the earliest C2065 in the list first — later errors often cascade from the same root cause.
Can a missing semicolon on the previous line cause C2065?
Yes — a missing semicolon at the end of a class or struct definition is a classic cause. The compiler reads the next statement as a continuation of the class, making the identifiers after it look undeclared. Always fix errors from the top of the list down.