Ad Space — Top Banner

E2401

C++ Builder Programming Language

Severity: Minor

What Does This Error Mean?

E2401 means you tried to use a class or struct that was only forward-declared — not yet fully defined — in a context that requires knowing the type's size. Creating an instance, passing by value, or taking sizeof all require the full definition. The fix is to include the header that provides the complete class definition before the line that triggers E2401.

Affected Models

  • C++ Builder 10.x (Alexandria)
  • C++ Builder 11 (Sydney)
  • C++ Builder 12 (Athens)
  • RAD Studio 11 and 12

Common Causes

  • A .cpp file uses a type that was forward-declared in the corresponding header but the full header was not included in the .cpp
  • A circular include was resolved by removing an include and replacing it with a forward declaration in the wrong file
  • Dereferencing a pointer to a forward-declared class (which requires the full definition to call members)
  • Declaring a stack-allocated variable of a forward-declared type

How to Fix It

  1. Add the full #include for the missing type in the file where E2401 fires. The forward declaration tells the compiler the type exists, but the full include tells it how big and what members it has.

    Forward declarations work for pointers and references only. For stack objects, member objects, and most operations, you need the full definition.

  2. If removing the forward declaration creates a circular include, restructure the headers. Move the class definition to a smaller, dedicated header that can be safely included by both files.

    Breaking a large header into smaller focused headers is the standard solution to circular include problems. Alternatively, the PIMPL (pointer to implementation) pattern completely eliminates the need for the full type in headers.

  3. Check Project Options to ensure all required library include paths are listed. E2401 can also appear when a library header is missing from the Include Path and only a stub forward declaration was found.

    Go to Project > Options > Building > C++ Compiler > Paths and Defines > Include Path. Add any library include directories that your project uses.

Frequently Asked Questions

Why can I use a pointer to a type but not an object of that type?

A pointer is always the same size (4 or 8 bytes) regardless of what it points to. The compiler does not need to know the full type to allocate space for a pointer. An object requires knowing the exact size and layout so the compiler can allocate the right amount of memory on the stack or inline in another struct.