CppPilot

Compiler diagnostic Visual Studio C++

C2061 syntax error: identifier

The compiler found a name where it expected a type it knows, most often in the parameter list of a function.

Applies toMSVC on Windows; code and debugger concepts apply to MSBuild and CMake
ExamplesFocused excerpts; required context is stated alongside each example

Visual Studio property-page paths describe MSBuild projects. For CMake, configure the corresponding target or preset. Menu names can vary by Visual Studio version; use the cited reference for your toolset.

Build output
error C2061: syntax error: identifier 'Widget'

Causes & corrections

Find the case that matches your build. Each example shows what changes and why.

  1. The type is not declared at that point.

    Include its header before the declaration, or qualify it with its namespace, for example std::string.

    Problem

    void draw(Widget* widget);// Widget is unknown here

    Correction

    class Widget;void draw(Widget* widget);
    Note 1Declare the parameter type before the function or include its header.
    VideoFilmed in Visual Studio: this case fixed by hand, then with CppPilot. English narration, with subtitles in English, French, German, Italian and Spanish.
    Transcript

    C2061, syntax error, identifier: fixed by hand, then with CppPilot. Logger::Write takes a string parameter.

    <string> is included, but string lives in the std namespace: in the parameter list, the compiler does not know this name, and reports C2061. Qualify the type with its namespace: std::string.

    Build again: the compiler finds std::string, and the build succeeds. Now the same error, fixed by CppPilot.

    After the failed build, select the error in the Error List, and click Fix with CppPilot. Click Fix on the C2061 card.

    The AI sees that string is used without its namespace, and writes std::string. CppPilot rebuilds the project to check the fix: the error is resolved.

    CppPilot explains and fixes C++ build errors in Visual Studio.

  2. Two headers include each other.

    With a circular include, the type is not declared yet. Forward-declare it (class Widget;) when the function takes a pointer or a reference, and include the header in the .cpp file.

    Problem

    // renderer.h and widget.h include each othervoid draw(Widget& widget);

    Correction

    // renderer.h#pragma onceclass Widget;void draw(Widget& widget);// renderer.cpp includes widget.h
    Note 2A reference parameter permits a forward declaration that breaks the include cycle.
  3. A dependent type in a template has no typename.

    Write typename T::value_type: inside a template, a name that depends on a template parameter is not a type unless you say so.

    Problem

    template<class T>void visit() {    T::value_type value{};}

    Correction

    template<class T>void visit() {    typename T::value_type value{};}
    Note 3typename identifies a dependent type in this declaration context.

Sources and scope

Official references

These links document the compiler, build system, or debugger behavior discussed here. Use the version selector on Microsoft Learn for your toolset. Example blocks are focused excerpts; required headers and build settings are stated alongside them.

In your workspace

Investigate C2061 with CppPilot

CppPilot gives the selected AI the diagnostic, relevant code, and project settings for the active configuration. Choose Fix to request a correction, then check the result with a rebuild.

Use your own Codex or Claude account, or optional CppPilot Cloud access. Setup instructions

Visual Studio Marketplace