Solved

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

Posted on 2004-04-13
2
17,461 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
no14 challenge 14 66
constructor while deserilizing object 16 56
copyEndy  challenge 15 94
allswap challenge 6 96
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

808 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