Well I got an error earlier today and I've been trying to solve it the whole day already.. But I don't understand what the error means and I can't find any syntax problems:
1>...\player.h(2) : error C2011: 'Objects' : 'class' type redefinition
1> ...\player.h(2) : see declaration of 'Objects'
Uhm you lost me there: I didn't really look into the macros yet. So I need to put this around everything to make sure a librarie isn't declared multiple times?
You need to use this technique in header files. This is because multiple source files in one program can include the same header effectively defining the same class multiple times in one program, i.e. each time the header is included.
put lines 1 and 2 of Zaita's post before any code in your header files and line 6 as the last line of the header. don't use the same define name more than once, the usual convention is to tie the define name to the file name.
Thanks for the help. Makes you think why the compiler doesn't automatically only include every file 1 time (what's the point of including the same thing twice)
Anyway, working a bit more yields yet another error:
#ifndef OBJECTS_H
#define OBJECTS_H
#include "field.h"
class Objects
{
public:
int x,y;
Objects(int xx, int yy,field* f, char c=' ')
{
x=xx;
y=yy;
mychar = c;
myfield = f;
}
char draw();
void set(int xx,int yy)
{
x = xx;
y = yy;
}
protected:
char mychar;
field *myfield;
};
#endif
Yields with an error player.h(10) : error C2061: syntax error : identifier 'field'
What does this mean lol? Doesn't this happen if "field" isn't declared already? - Yet I know it is (and I know it's working) - cause in the main code I have this:
1 2 3
playfield = new field(ww,hh);
mainplayer = new Object(1,1,playfield,'O');
playfield->set(mainplayer,mainplayer->x,mainplayer->y,playfield);
Which DOES work, if I leave out the third argument it works....
Mostly because it's not the compiler that does the inclusion, but the preprocessor, which is not known for its smartness (not that it should be any other way).
How about posting the code that produces the error?
Assuming that your field.h is the complete file, you haven't got an #endif at the bottom of the file. This is going to give you weird problems (which is what you have)