I saw this question and I tried to do as the answer to that question said. To use the extern keyword in the header file to define an array and then declare it outside of that namespace or class in a other cpp file.
It didn't work for me really, I'm not sure if it because I'm using a void pointer array (i.e void* array[]) or if it's just my ignorance that prevents me from seeing the problem.
This is the shortest example I can come up with:
[cpp.cpp]
#include "h.h"
void main(){
void* a::b[] = {
a::c = a::d(1)
};
}
[h.h]
namespace a{
struct T* c;
struct T* d(int e);
extern void* b[];
}
So the problem is that I receive the error: IntelliSense: variable "a::b" cannot be defined in the current scope
And I have no clue why that is.
intis one character shorter thanvoid...a::bis declared outside of a function, the definition should be outside as well, why are you writing it insidemain?void main()you deleted the reasoning for why you typed something incorrect to begin with. Brilliant. And the definition ofa::bneeds to be at namespace scope, not block scope.void main, because then I don't have to return anything.int main() { ... }