Public Group

#### Archived

This topic is now archived and is closed to further replies.

# class redifinition error

This topic is 5804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
yeah thats what i was getting at...but VC++ and most other popular compilers support it...maybe not like gcc or mingw...

##### Share on other sites
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]

##### Share on other sites
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]

##### Share on other sites
Nevermind I fixed the already has body error. Thanks for the people who replied.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009849
• ### Who's Online (See full list)

There are no registered users currently online

×