externconstint MAX_OBJ_VERBS;
struct v_data {
int theData[MAX_OBJ_VERBS];
};
Okay, so I'm getting errors upon compiling like "error C2057: expected constant expression", and, "warning C4200: nonstandard extension used : zero-sized array in struct/union".
Now, what I DON'T want to do is the "#include "verbs.h"" within the main.h file.
How can I get MAX_OBJ_VERBS to be valid in main.h without including verbs.h?
Compilers only compile .cpp files, the .h files are ignored completely. You have to #include the .h files you want compiled in at least one .cpp file. In your case, line 14 of verbs.h should actually be in a .cpp file and not in a .h file.
The way it works is that actual definitions (line 14 of verbs.h) can only exist once, and declarations (line 1 of main.h) can exist any number of times. Since headers are usually included multiple times, you shouldn't put actual definitions in them, only declarations.
Very good point. I never stopped to consider that .h files weren't compiled. That really clears some confusion for me.
My goal is simple. I want to be able to add verbs to the enum list and then be able to compile the program without every single .cpp that has include main.h in it.
I'm not misunderstanding enumerations and arrays. I'm using an enum purely as an alternate option.
I fully realize that I could just as well have:
1 2 3
constint a = 1;
constint b = 2;
constint c = 3;
etc. etc...
I don't even mind if that's how it actually is. The goal is to be able to have MAX_OBJ_VERBS change according to how many verbs I add and/or take away.
The code actually used to be like this (in main.h):
And life was good. But then from day to day I would always add and/or delete a verb, which in turn MAX_OBJ_VERBS would need to change to.
Now, for the 5 or so .cpp files that needed CUDDLE, EMBRACE, FLIP, GROPE and HUG, and the other 140+ .cpp files that needed v_data.theData[], I was/am trying to be able to add verbs without a 10 minute compile time.
Neither, because you should remove the "zero" and not subtract 1. The only reason I casted was because, technically, enums are a new type (even though they use int by default).
I need the "zero" in there as a place holder, so, it has a purpose. I personally favor the idea of type casting (OBJ_VERBS::zTOTAL - 1), so I'm leaving it constint _MAX_ = int(OBJ_VERBS::zTOTAL - 1);.