Possible Duplicate:
Why does const imply internal linkage in C++, when it doesn’t in C?
If I have the following:
a.cpp:
const int ArrayOfInts[] = {1, 2, 3, 4, 5};
b.cpp:
extern const int ArrayOfInts[];
void SomeFunc()
{
int a = ArrayOfInts[0];
}
The linker complains that ArrayOfInts is unresolved from b.obj. Removing the const qualifier makes the link succeed. Any ideas why this fails?
Thanks.
When the compiler compiles
b.cpp, for all it knows, the value ofArrayOfInts[0]could be anything. So it’s not a compile-time constant. In C++, constants at file scope are compile-time constants by default.