PDA

View Full Version : C++ help on: Redefinition of class, but the only definition



Sp˙rL
April 25th, 2009, 10:30 PM
Ive split the class into a seperate .h and .ccp for the implementation of things.
I have the class definition in the .h and thats the only time I use the key word class as Im obviously creating a class.
I coded these originally in notepad (lol), but since have run it through Dev-C++ (4.9.9.2). I fixed a majority of the errors that were bound to be in it, however I have this error that it keeps throwing at me during build-time saying:

line 13: redefintion of 'class Details'then below that error it has:

line 13: previous definition of 'class Details'as you can see.. the apparent redefinition is actually the original definition of the class. It also happens to be the only definition.. Can anyone explain whats going on here?

If possible, can I get clarification on how to properly include the seperate .h and .ccp files and which files need #include statements and the #ifndef statements, as I dont think Im 100% on what should be where.

Thanks guys.

actionAction
April 27th, 2009, 04:39 PM
Your main file and your Details.cpp file should both include the Details.h file. In your Details.h, the class definition should be within this:


#ifndef DETAILS_H
#define DETAILS_H

//CLASS DEFINITION HERE

#endif


Make sure there is a semi-colon after the closing curly bracket at the end of your class definition in the .h file.

-aA

Sp˙rL
May 21st, 2009, 11:29 PM
Thanks action.

I havent been on in a while, but I managed to work out what the cause was,
I have the #endif statement immediatly following the #define statement.. haha, silly me.

I do have another queston about the #define statement (in general).
Is there actually any difference between the following two pieces of code:



#ifndef DETAILS_H
#define DETAILS_H
//(What I coded)

and



#ifndef DETAILS_H_
#define DETAILS_H_
//(eclipse auto generated code for a .h file)



Eclipse has an underscore following the 'H'.
Is it good practise to do that, or does it not matter?

MTsoul
May 22nd, 2009, 01:50 AM
Try not to rely on an IDE/editor to do that for you. It doesn't matter what it is, as long as it's consistent through our your project. Personally I don't have the final underscore.