Right I don't know why these errors are occuring at all so I'm just gonna post code and errors and hope someone can help me?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Object{
public:
//class variables
//First lot of errors
static Object* firstObejct;//Start of internal list
static Object* lastObject;//End of internal list
Object* prevObject;//Pointer to previous Object
Object* nextObject;//Pointer to next Object
public:
//Second lot of errors
Object();
Object(float arg[]);
Object(Object &c);
virtual ~Object();
};
//First Errors
5 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `firstObejct' with no type
6 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `lastObject' with no type
7 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `prevObject' with no type
8 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `nextObject' with no type
//Second Errors
11 ...\Project\Classes\Object.cpp expected unqualified-id before ')' token
12 ...\Project\Classes\Object.cpp expected unqualified-id before "float"
12 ...\Project\Classes\Object.cpp expected `)' before "float"
13 ...\Project\Classes\Object.cpp expected class-name before '(' token
14 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `c' with no type
14 ...\Project\Classes\Object.cpp `c' declared as a `virtual' field
//First Errors
5 ...\Project\Classes\Object.cpp ISO C++ forbids declaration of `firstObejct' with no type
The 5 suggests that these are not, in fact, your first errors. Given that "first" errors often affect what may be listed as errors after them, the "first" errors are probably the ones you need to correct, and not the ones you have listed here.
Yes silly me, the chapter on polymorphism in my book mentions about calling constructors from derived classes, it only mentions using destructors and other general functions as virtual...
Whoopsy.
I'll correct this when I'm next on my computer and hopefully the pointers will correct too! I'll let you know if it works, cheers!
Ok, I didn't think there should be any errors remaining... This is my full class (of declarations, the definitions are outside the class) and there are more errors related to other things but I thought I'd try sort 1 thing out at a time.
class Object{//1 ...\Project\\Classes\Object.cpp an anonymous union cannot have function members
private:
constint id;
const string type;
//4 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::type' with constructor not allowed in anonymous aggregate
//4 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::type' with destructor not allowed in anonymous aggregate
//4 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::type' with copy assignment operator not allowed in anonymous aggregate
const string name;
//8 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::name' with constructor not allowed in anonymous aggregate
//8 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::name' with destructor not allowed in anonymous aggregate
//8 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::name' with copy assignment operator not allowed in anonymous aggregate
const string image;
//12 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::image' with constructor not allowed in anonymous aggregate
//12 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::image' with destructor not allowed in anonymous aggregate
//12 ...\Project\\Classes\Object.cpp member const std::string <anonymous class>::image' with copy assignment operator not allowed in anonymous aggregate
constfloat sizeBounds[2];
float pos[3];
staticint numObjects;
static Object* firstObejct;//20 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `firstObejct' with no type
static Object* lastObject;//21 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `lastObject' with no type
Object* prevObject;//22 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `prevObject' with no type
Object* nextObject;//23 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `nextObject' with no type
public:
Object();//25 ...\Project\\Classes\Object.cpp expected unqualified-id before ')' token
Object(float arg[]);
//26 ...\Project\\Classes\Object.cpp expected unqualified-id before "float"
//26 ...\Project\\Classes\Object.cpp expected `)' before "float"
Object(Object &c);//29 ...\Project\\Classes\Object.cpp expected `)' before "float"
virtual ~Object();//30 ...\Project\\Classes\Object.cpp expected class-name before '(' token
float resolveRotation();
int getId();
string getType();
string getName();
string getImage();
float getSizeBound(int art);
float getPos(int arg);
float getRotation();
int getNumObjects();
Object& getFirstObject();//40 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `getFirstObject' with no type
Object& getLastObject();//41 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `getLastObject' with no type
Object& getNextObject();//42 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `getNextObject' with no type
Object& getPrevObject();//43 ...\Project\\Classes\Object.cpp ISO C++ forbids declaration of `getPrevObject' with no type
int setPos(float arg[]);
void setRotation(float arg);
void resetRotation();
};
#include <stdio>
#include "Headers/Object.h"
int main(){
printf("\nIn app pause.\nPress enter to continue.\n");
getchar();
return 0;
}
As you can see there is literally nothing in the main class of yet, I have done this so that the compile log I get is for the Object class only... If it compiles correctly all of Object.cpp will be ignored anyway as it isn't used and I will get a Dow window prompting me to hit enter.
//1 ...\Project\\Classes\Object.cpp an anonymous union cannot have function members
This error implies that there's something wrong in a file that's included by "Object.cpp", which is causing the subsequent errors. Since the compiler is complaining about the class declaration itself, the actual issue is almost definitely before that. Perhaps you've missed a semicolon or a closing brace somewhere?
There are no errors appearing at all about constant variables... Also this is supposed to be a abstract class from which I create more things and properly define all the constants as well as the definition in this class.
I've update the above post to add the other files included in compilation.
Oh yeah, I'm using Dev-C++ 4.9.9.2 if that helps at all?
#define Object
That is the problem.
You see, when you do #define Something SomethingElse it will replace all instance of Something with SomethingElse
In your case it is #define Object <nothing> so all instances of "Object" will be deleted. First lines of your file would be like this:
1 2 3
class { //That is an defiition of anonymous class (or struct)
private:
//...
Change your header guard to something else (OBJECT - all uppercase - will be enough)
And I cannot not to tell that you did headers wrong: if you try to use it in more than one file, you will get linker errors.
Oh of course! The macros!
Well that's great... Now I'm getting lots and lots of other random errors about constants and undeclared/undefined variables. So at least I've got passed that part, thanks guys!
I'll update anything I can't fix from here on in... Again cheers!
Also how would you suggest creating the header, I didn't fully understand the tutorial on here so I tried to at least make sure I could avoid some errors (the current header should stop including the same file twice and creating infinite loops between includes at least)