expected class-name C/C++ Origin: Application & API OSI layer 7 · Application Last updated 28 Nov 2026

C++: error: expected class-name before '{' token

A base-class list or declaration expects a class name but found something else.

Exact message you may see expected class-name beforeexpected class-nameinvalid use of incomplete base class
Seen on: C/C++ GCC Clang

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

  1. Include the header that defines the base class
  2. Qualify the namespace
  3. Break circular includes with forward declarations in headers

Detailed fix by platform

GCC / Clang

  1. Add #include "base.h" above the derived class and use include guards or #pragma once

How to diagnose

  1. Header — Is the base class defined before this line?
  2. Name — Spelling and namespace?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

cannot bind non-const lvalue reference — C++: error: cannot bind non-const lvalue reference of type 'T&' to an rvalue of type 'T' (C/C++)cannot bind non-const…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…case label does not reduce to an integer constant — C/C++: error: case label does not reduce to an integer constant (C/C++)case label does not r…conflicting types — C: error: conflicting types for 'foo' (C/C++)conflicting typesdiscards qualifiers — C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive] (C/C++)discards qualifiersincomplete type — C++: error: invalid use of incomplete type 'class X' — forward declaration only (C/C++)incomplete typeis private within this context — C++: error: 'int X::secret' is private within this context (C/C++)is private within thi…No CMAKE_CXX_COMPILER could be found — CMake Error: No CMAKE_CXX_COMPILER could be found (C/C++)No CMAKE_CXX_COMPILER…expected …

Explore the map of this error Full error map →

🧠 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.