• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17509
  • Last Modified:

Error C2011 in Visual C++ 6.0 ('struct' type redefinition)

Hi-

I'm trying to write a small program that will "ping" in a Windows environemnt using rawping.
When I try to build the project I get the error messages:

c:\ folder\subfolder\project name\rawping.h (line number) : error C2011: 'IPHeader' : 'struct' type redefinition

and

c:\folder\subfolder\project name\rawping.h (line number) : error C2011: 'ICMPHeader' :'struct' type
redfinition

I haven't been able to find much information about  error C2011 . I understand that a structure is the same as a class except that its members are public by default.

I am assuming that  a 'struct' can be defined only once but not sure when / where it is defined.

Both 'IPHeader' and 'ICMPHeader' appear in 3 different files: rawping.cpp, rawping.h and rawping_driver.cpp .

My questions: assuming a 'struct' can be defined only once, when/where should it be defined?
(as the error appears in the header file, I'm guessing the compiler found the 'struct' in one of the .cpp files)

What other references to IPHeader and ICMPHeader need to be removed?

Any help will be appreciated.

Thanks,

Charley
 
0
Charley50
Asked:
Charley50
  • 2
1 Solution
 
sunnycoderCommented:
You are right ... struct can be defined only once ... Best option is to define it in a header file and include that header file in all the .c or .cpp files that need it
0
 
sunnycoderCommented:
Remove all definitions of the structs which give error from c/cpp files and keep them (the struct declarations) in the header files
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now