Ad Space — Top Banner

C3861

Visual C++ Programming Language

Severity: Minor

What Does This Error Mean?

C3861 means the compiler encountered a name and could not find any declaration for it, even after argument-dependent lookup (ADL) in the namespaces of the arguments. The message reads: C3861: 'identifier': identifier not found. It is similar to C2065 but specifically indicates that ADL also failed — common with free functions and template functions. The fix is to declare or include the identifier before the point of use.

Affected Models

  • Visual Studio 2015–2022
  • MSVC v14.x / v17.x

Common Causes

  • A free function is called before it is declared or defined in the translation unit
  • A missing #include for a header that declares the function
  • A function template is called but its definition is in a .cpp file instead of a header
  • A using declaration or using namespace directive is missing
  • The function is defined after the call site and no forward declaration exists

How to Fix It

  1. Add the required #include at the top of the file. If the function comes from a library or another part of your project, its header must be included before the call.

    C3861 names the identifier — search your headers and source files for a declaration of that exact name to find which header to include.

  2. If the function is defined in the same file but after the call site, add a forward declaration before the call or move the definition above the call.

    C++ requires identifiers to be declared before use in the same translation unit. A forward declaration (return_type functionName(params);) is enough to satisfy the compiler.

  3. For function templates, make sure the full template definition is in the header file, not in a .cpp file. Templates must be visible at the point of instantiation.

    Template definitions in .cpp files are a very common source of C3861. Move the template body to the header or add an explicit instantiation in the .cpp for each type you use.

Frequently Asked Questions

What is the difference between C3861 and C2065?

C2065 fires when a name is not found in normal name lookup. C3861 fires when a name is not found even after argument-dependent lookup, which extends the search to namespaces associated with the function arguments. In practice both errors mean the same thing: include the header or declare the identifier before use.