Moving a void to a .cpp file

I'm apologizing in advance for the long code.

I'm trying to move a void to another file (for organization) but then i need to include all of its variables and stuff it needs. When i include .h file then i get it saying everything has been defined twice. Since that didn't work i reverted back to one file. I do have it declared however that is in another .h file. Right now in one file it works but i need it another file.

How can i split this up so the void is in a separate file?

The Code:
Link removed - solved see the third reply

Lines 34-70 are needed by the void
Lines 176-332 are the void
Last edited on
even, suggestions or ideas would be helpful
Declare the global variables with extern in the header file.
1
2
3
4
extern SDL_Event event;
extern float width;
extern float height;
...
and define them in a source file like you have already done.

Put a declaration of the functions you want to use in other files in the header.
void BreakBrickRunning();
I'm having trouble with the this:

1
2
extern const static int BRICKS;
Brick bricks[BRICKS];


Error:

1
2
3
conflicting specifiers in declaration of 'BRICKS'|
'BRICKS' was not declared in this scope|
||=== Build finished: 2 errors, 0 warnings ===|



and if i remove static in both files i get this error:

1
2
array bound is not an integer constant|
||=== Build finished: 1 errors, 0 warnings ===|





UPDATE


however if i replace it to... It works:
1
2
extern const int BRICKS;
extern Brick bricks[45];


it must have been something about there being no value to BRICKS yet.

If anyone knows how to still leave that as a variable it would help
Last edited on
When you declare an array the size must be known. here BRICKS is not known yet so that is why you get an error. Constants is a bit special so you can define it in the header without using extern. Doing this will fix the problem.

global constants are implicitly static so you don't have to use static here. This is actually the reason why it's fine to define the constants in the header.
Last edited on
Topic archived. No new replies allowed.