Why does the linker always seem to stall any attempt at progress at every possible moment! I have an extern Three-dimensional array and I (after review of course) cannot find what is causing the problem.
int Render::RenderChunk(int posX, int posY, int posZ, int ViewPointX, int ViewPointY, bool WireFrame )
{
int CurrentBlock;
for(LoopCount x = 0; x <= CHUNK_SIZE + 1; x++)
{
for(LoopCount y = 0; y <= CHUNK_SIZE + 1; y++)
{
for(LoopCount z = 0; z <= CHUNK_SIZE + 1; z++)
{
CurrentBlock = World[x][y][z];
RenderBlock(x + CHUNK_SIZE*posX, y + CHUNK_SIZE*posX , z + CHUNK_SIZE*posX , ViewPointX, ViewPointY, WireFrame, CurrentBlock);
} // Z
} // Y
} // X
return 0;
}
Why can I not use this external array in other functions/files?
Note* The includes are all correct, that is not the error.
extern is used to declare a variable it binds a variable which is already defined or later.
You must define a variable before building your application.
If you are building a library it is not necessary to define that variable, When you are going to use that library in any other application you must define that variable.
What would cause the linker to give an unresolved external.
The variable not being defined. It is not defined there, it is only used. How can you use it without it being defined? You can't. Thus, the linker error.
In Map.cpp you need the following line somewhere at global scope:
Alright that makes sense, however how would I go about the problem of using the same array in multiple files? I would get an already defined error from the linker.
WorldGenerator.obj : error LNK2005: "int (* World)[300][100]" (?World@@3PAY1BCM@GE@HA) already defined in RenderBlock.obj
To be exact...
On a side note is there any problem with #pragma once at the start of cpp's?
Alright that makes sense, however how would I go about the problem of using the same array in multiple files?
There is no problem. You simply #include the header file with it's declaration and there are no redefinition issues (because the variable is not defined in the header.)
On a side note is there any problem with #pragma once at the start of cpp's?
Since you shouldn't #include cpp files, there is no reason to.