Compiler Error C2065

'identifier' : undeclared identifier

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.

Possible causes:

  1. You are compiling with a debug version of the C runtime, declaring a Standard C++ Library iterator variable in a for loop, and then trying to use that iterator variable outside the scope of the for loop. Compiling Standard C++ Library code with a debug version of the C runtime implies /Zc:forScope. See Debug Iterator Support for more information.

  2. You may be calling a function in an SDK header file that is currently not supported in your build environment.

  3. 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.)

  4. Identifier name is misspelled.

  5. Identifier uses the wrong uppercase and lowercase letters.

  6. Missing closing quote after a string constant.

  7. Improper namespace scope. To resolve ANSI C++ Standard Library functions and operators, for example, 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:

Example

The following sample generates C2065.

// C2065.cpp
// compile with: /EHsc
// using namespace std;
#include <iostream>
int main() {
   cout << "Hello" << endl;   // C2065

   // try the following line instead
   std::cout << "Hello" << std::endl;
}

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.

The following sample generates C2065.

// C2065_b.cpp
// compile with: /clr
generic <typename ItemType>
void G(int i) {}

int main() {
   // global generic function call
   G<T>(10);   // C2065
   G<int>(10);   // OK
}

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. See Breaking Changes in the Visual C++ 2005 Compiler for more information.

The following sample generates C2065.

// C2065_c.cpp
// compile with: /c
[module(DLL, name=MyLibrary)];   // C2065
// try the following line instead
// [module(dll, name="MyLibrary")];

[export]
struct MyStruct {
   int i;
};