E2108
C++ Builder Programming Language
Severity: MinorWhat Does This Error Mean?
E2108 means a typedef alias was used in a context where a typedef name is not permitted by the C++ grammar. Common examples include using a typedef name as a constructor call in certain contexts, or using it in elaborated type specifiers such as struct TypedefName. The fix is to use the original underlying type name, or to restructure the declaration to use the typedef correctly.
Affected Models
- C++ Builder 10.x (Alexandria)
- C++ Builder 11 (Sydney)
- C++ Builder 12 (Athens)
- RAD Studio 11 and 12
Common Causes
- Using a typedef name with an elaborated type specifier (struct or class keyword before the typedef name)
- Attempting to use a typedef name as a constructor tag in placement new or similar contexts
- A typedef and a struct have the same name but are used interchangeably in contexts that require the original struct name
- Legacy C code ported to C++ where typedef struct patterns are used differently than the C++ grammar allows
How to Fix It
-
Remove the struct or class keyword before the typedef name. In C++, a typedef already stands for the full type — adding struct in front is redundant and causes E2108.
In C, struct MyStruct requires the struct keyword. In C++, a typedef eliminates this requirement. Write MyType, not struct MyType, when MyType is a typedef.
-
If the typedef and the struct tag have the same name, be consistent. In C++, you can use just the name — you do not need the struct keyword prefix even for non-typedef struct names.
C++ automatically registers struct tag names in the same namespace as other type names. You only need struct if there is a non-type identifier with the same name (a function or variable).
-
For legacy C code, consider replacing typedef struct patterns with a simple C++ struct or class definition. Modern C++ struct definitions are cleaner and do not require typedef.
The C idiom typedef struct _Tag { ... } TypeName; is unnecessary in C++. Replace it with just struct TypeName { ... }; for cleaner code.
Frequently Asked Questions
Does E2108 appear when using Delphi-style types in C++ Builder?
It can. Delphi types that are exposed to C++ Builder sometimes use typedef patterns generated by the IDE. If you copy-paste Delphi type names into C++ declarations, the C++ compiler may reject the combination. Use the auto-generated C++ header types (from the .hpp files in the project output) rather than the Delphi names directly.