I've just been copying and pasting my headers to each .h and .cpp file. Guessing this is wrong. Do i need to include guards somewhere? or which headers need to me removed?
I mean like do i need to place #ifndef SOMETHING_H and #define SOMETHING_H somewhere. Also the error im getting is saying previous definition of struct tm and redefintion of tm in time.h and wchar. which arent in my project.
That file has include guards. There is a preprocessor if-block that contains lines 2--21.
The block is read only if preprocessor macro "CLUB_H" has not been defined already.
Line 2 defines that macro and therefore lines 2--21 will not be read more than once.
The CLUB_H looks unique enough. In fact, if it not were unique, then some other unrelated header would not be read even once, leading to undefined symbol errors.
I do suggest that you do reorder your includes. Move the standard headers (in <>) before project's headers. That way the redefinition should occur in your files.
Please show the Cbros.h too. We want to see whether the iostream and string are both necessary for it.
Last, the compiler error messages contain line-numbers. You need to know which line in your code offends the compiler.
@keskiverto
Think the issue is in my main.cpp. I include Club.h in there so i can initialize an object to get the game started. as show below. The program runs with <ctime> if i delete Club.h out of main.cpp though.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "Club.h"
#include <ctime>
usingnamespace std;
int main(){
Club Club1;
Club1.displayMenu();
Club1.processInput();
}
#endif // CLUB_H
However, if you do need the <ctime>, etc, put them first:
Putting standard headers first masks the situation where user headers don't properly include what is needed in them. I've taken to doing things the other way 'round.
The using namespace std directives in headers is the most likely cause of the issue here. If you must use such directives, do so only in source files.