Jump to content
  • Advertisement

Archived

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

Nothingness

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 here
class 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!