Advertisement

class redifinition error

Started by December 02, 2002 06:50 PM
5 comments, last by Nothingness 21 years, 11 months ago
I made a class and saved it as a .h file, but wheni make the main file, it says that it is a ''class'' type redifinition. I have know idea why that is happening can someone help?
try putting #pragma once at the top of the .h file. You may be including the .h file more than once, which would cause class redefinition. An inclusion guard like #pragma once (you can also do it with preprocessor conditionals, but most new compilers support pragmas) will make sure each header is only included once in each code segment.
Brian J
Advertisement
or, if you want standard compatibility between compilers (i think that pragma commands are compiler specific...) wrap your .h file in some kind of #ifndef #define #endif tags like the following

#ifndef _CLASS_YOURCLASSNAME#define _CLASS_YOURCLASSNAME//contents of .h file hereclass YourClassName {};#endif 


all that means is that if the constant _CLASS_YOURCLASSNAME is not already defined, define it and include the enclosed code. your problem is that you are including in your file a .h file that is also included by another of the .h files that you are #including. the system above avoids re-includes of the same code during compile.

-me
yeah thats what i was getting at...but VC++ and most other popular compilers support it...maybe not like gcc or mingw...
Brian J
Yeah thanks for the help, i did that and it worked. I have another error it says that one of my functions "already has a body" but it dosnt. I don't know how to fix that either. Its in another cpp file BTW.

[edited by - Nothingness on December 2, 2002 8:18:47 PM]
quote: Original post by bjmumblingmiles
yeah thats what i was getting at...


damn. my reading comprehension today is zero. i don't think i even read the sentance where you commented on compiler specificity. heh.

-me

[edited by - Palidine on December 2, 2002 8:19:08 PM]
Advertisement
Nevermind I fixed the already has body error. Thanks for the people who replied.

This topic is closed to new replies.

Advertisement