Solved

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

Posted on 2004-04-13
2
17,463 Views
Last Modified: 2012-08-14
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
Comment
Question by:Charley50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10820570
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
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 10820609
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 127
MaxSpan challenge 9 124
Line meaning 9 91
What language/protocol is the Angular Chat? 2 95
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question