MSVC build errors > C2011
C2011: type redefinition
error C2011: 'sockaddr': 'struct' type redefinition
The compiler saw the definition of a class, struct, or enum twice in the same file, usually through headers.
Causes and fixes
- A header has no include guard. Add
#pragma onceat the top of the header, so that including it twice defines its types once. - Two headers define the same type. Keep one definition, in one header, and include it from the other.
windows.his included beforewinsock2.h.windows.hincludes the oldwinsock.h, which redefinessockaddr: includewinsock2.hfirst, or defineWIN32_LEAN_AND_MEANbeforewindows.h.
Fix C2011 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: C4430. See all guides.