E2304
C++ Builder Programming Language
Severity: MinorWhat Does This Error Mean?
E2304 means the compiler needs to know the full size and layout of a struct but only has a forward declaration available at that point. The message reads: E2304 size of struct 'name' is unknown. This is the struct-specific counterpart to E2401 (unknown class size). The fix is to include the header that fully defines the struct before the line that uses it.
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 attempts to use a struct by value when only a forward declaration is in scope
- sizeof is called on a forward-declared struct
- A struct is used as a member of another struct that is defined before the member struct is fully declared
- A Windows API struct (like WNDCLASSEX or OVERLAPPED) is used without including the correct Windows header
How to Fix It
-
Include the header that contains the full struct definition before the line that triggers E2304. A forward declaration alone is not enough for any operation that requires the struct size.
Forward declarations work for struct pointers and references only. Declaring a struct variable, passing by value, or calling sizeof all require the full definition.
-
For Windows API structs, make sure windows.h (or the specific Windows sub-header) is included. Many Windows structures require specific headers.
Include windows.h at the top of the .cpp file that uses Windows structs. For VCL applications, windows.h is often included transitively through vcl.h — verify vcl.h appears before the code that uses the struct.
-
Check include order in the .cpp file. The full struct header must come before the code that creates or uses the struct, not after.
C++ processes includes in order. If another header included later provides the full definition, that is too late for code that appears before it.
Frequently Asked Questions
Is E2304 the same as E2401?
They are closely related — E2401 applies to classes and E2304 applies to structs. In C++ the distinction between class and struct is minimal (only default access level differs), so the fixes are identical: include the full definition header before the point of use.