C++: error: expected class-name before '{' token
A base-class list or declaration expects a class name but found something else.
expected class-name beforeexpected class-nameinvalid use of incomplete base class Meaning
The compiler did not recognise the name after : in class D : public Base. Usually Base is not declared yet (missing include or forward declaration only), or it is misspelled or in another namespace.
Common causes
- Base class header not included
- Forward declaration used where a full definition is needed
- Misspelled or wrong-namespace base class
- Circular includes
⚡ Quick fix
- Include the header that defines the base class
- Qualify the namespace
- Break circular includes with forward declarations in headers
Detailed fix by platform
GCC / Clang
- Add
#include "base.h"above the derived class and use include guards or#pragma once
How to diagnose
- Header — Is the base class defined before this line?
- Name — Spelling and namespace?
- Cycle — Circular includes?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- cannot bind non-const lvalue reference C++: error: cannot bind non-const lvalue reference of type 'T&' to an rvalue of type 'T'
- cannot declare variable to be of abstract type C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions)
- case label does not reduce to an integer constant C/C++: error: case label does not reduce to an integer constant
Most viewed in C/C++
- Bus error C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 28 Nov 2026