Compiler diagnostic Visual Studio C++
C2143 syntax error: missing ';' before
The compiler stopped at a token it did not expect. The missing ; is often not the real problem: most of the time, the word just before the reported token is a type name the compiler does not know at that point.
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.
error C2143: syntax error: missing ';' before '*'Causes & corrections
Find the case that matches your build. Each example shows what changes and why.
A type name is unknown.
In
Widget* widget;, ifWidgetis not declared, the compiler reads it as a variable and expects;before*. Include its header, qualify it with its namespace, or forward-declare it (class Widget;).Problem
// Widget has not been declaredWidget* widget;Correction
class Widget;Widget* widget;Note 1A pointer needs a declaration; constructing the object or accessing members requires its definition. VideoFilmed in Visual Studio: this case fixed by hand, then with CppPilot. English narration, with subtitles in English, French, German, Italian and Spanish. Transcript
C2143, syntax error, missing ';': fixed by hand, then with CppPilot. Window declares a Widget* member, but Widget is only defined below.
The compiler does not know the name yet, and reports C2143: missing ';' before '*'. The semicolon is not the problem.
A pointer only needs the name: forward-declare class Widget; before Window. Build again: the compiler now knows Widget, 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 C2143 card. The AI sees that Widget is defined after Window, and adds the forward declaration class Widget; above it.
CppPilot rebuilds the project to check the fix: the error is resolved. CppPilot explains and fixes C++ build errors in Visual Studio.
A class or struct definition does not end with
;.Write
};after the closing brace. The error then appears on the first line after the class, often in another file that includes the header.Problem
struct Point { int x; }int main() { return 0; }Correction
struct Point { int x; };int main() { return 0; }Note 2A class definition ends with a semicolon after its closing brace. Two headers include each other.
One of the two classes is not declared yet when the other uses it. Replace one include with a forward declaration where a pointer or a reference is enough.
Problem
// a.h and b.h include each other// b.h sees A before its definitionstruct B { A* parent; };Correction
// b.h#pragma onceclass A;struct B { A* parent; };Note 3Include the full A header in the implementation when its members are needed. The previous statement is not finished.
Look at the line before the one reported: a missing
;, an unclosed parenthesis, or a macro that expands to something unexpected.Problem
void run() { int count = 1 count += 2;}Correction
void run() { int count = 1; count += 2;}Note 4The compiler may point to the next statement rather than the missing semicolon.
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 C2143 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