C++/CLI: Public ref struct generates C2011: ‘class’ type redefinition

You have to de-tune the traditional C/C++ header file think a bit when you work with managed code. The principal source of type declarations is the assembly metadata. This is very different from the native C/C++ compilation model where you have to have a header file for types that you make visible to other modules.

I’m going to guess that you get this C2011 error in the EXE project. Where you both added a reference to the DLL project assembly (like you should) and used #include on the header file. Like you should not. That’s a guaranteed duplicate definition, #pragma once doesn’t fix that.

Don’t use header files for exported type definitions. Always use assembly references.

Leave a Comment