incomplete type C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: invalid use of incomplete type 'class X' — forward declaration only

You used a class that has only been forward-declared (so its size and members are unknown) where the full definition is required.

Exact message you may see invalid use of incomplete typeincomplete type is not allowedforward declaration of 'classmember access into incomplete typeallocation of incomplete type
Seen on: C/C++ GCC Clang

Meaning

A forward declaration (class X;) is enough for pointers and references, but not for creating objects, calling members, sizeof, delete, or deriving. Include the real header in the .cpp that needs it, and keep headers light by forward-declaring only what they truly need.

Common causes

  • Accessing members through a pointer when only class X; is visible
  • Circular includes (a.h includes b.h which includes a.h)
  • std::unique_ptr<X> member with X incomplete at the destructor
  • Using sizeof(X) or new X before the definition
  • Missing #include <vector> / <string> leaves std types incomplete

⚡ Quick fix

  1. #include "x.h" in the .cpp that uses the members
  2. Break include cycles with forward declarations in headers
  3. Define the destructor in the .cpp for pimpl classes

Detailed fix by platform

C++

  1. In headers use class X; and pointers/references; in the .cpp include the full header
  2. For std::unique_ptr<Impl> declare ~Widget(); in the header and define Widget::~Widget() = default; in the .cpp

Code examples

Forward declaration is not enough to call members

cpp
// a.h
class B;                       // forward declaration
struct A { B* b; void use(); };

// a.cpp
#include "a.h"
#include "b.h"                 // <-- required here
void A::use() { b->run(); }    // error without b.h: invalid use of incomplete type 'class B'

How to diagnose

  1. Declaration — Is the type only forward-declared where it is used?
  2. Cycle — Do the headers include each other?
  3. Needs — Do you need the size or members here?

🔧 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 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…discards qualifiers — C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive] (C/C++)discards qualifiersdoes not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typeimplicit declaration of function — C: warning: implicit declaration of function 'foo' [-Wimplicit-function-declaration] (C/C++)implicit declaration …is private within this context — C++: error: 'int X::secret' is private within this context (C/C++)is private within thi…multiple definition of — C/C++: multiple definition of `x'; first defined here — ld returned 1 exit status (C/C++)multiple definition ofredefinition of — C++: error: redefinition of 'class X' / multiple definition — missing include guard (C/C++)redefinition ofuse of deleted function — C++: error: use of deleted function 'X::X(const X&)' — copying a non-copyable type (C/C++)use of deleted functi…incomplet…

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.