I have one of my header files, that I have used before, #included in my
solution. It compiles ok and the linker/loader doesn't complain. I can load
this header file into the IDE window but I can't access any of the variables
from this file in my .cpp.
What does that mean? You can either #include a file in a source file, or add a file to a solution. You don't #include a file in a solution, that's a meaningless phrase.
If you merely added the header to the solution, that's a no-op for the toolchain. Header files are neither compiled nor linked. The only point of adding a header to a solution is to be able to edit it more comfortably, and possibly to assist the autocompletion tool. To use the declarations in it you still have to include it in a source file.
Sorry, I didn't put enough detail in my post. The actual line is:
#include "ScoreChart.h"
immediately under that line is:
#include "dirent.h"
both of these header file reside in the directory with the .cpp file. I have no problem with the
dirent.h file.
To move on with coding I put the entire contents of the ScoreChart.h file at the top of my .cpp.
Everything works that way but I don't want to leave it because it's a large file that doesn't belong there.
In ScoreChart.h there is a array named int majors[][6];
Here's a short version of my program.
#include "ScoreChart.h"
#include "dirent.h"
int main()
{
int* majorpnt;
majorpnt = &majors[0][0];
return 0;
}
I have used similar code with the same ScoreChart.h header file in other
programs. For some reason this variable and any other variables in
ScoreChart.h" aren't found by the compiler.
This works when I copy the ScoreChart.h into my .cpp file.
To move on with coding I put the entire contents of the ScoreChart.h file at the top of my .cpp.
Keeping it all as separate files is the norm, as you know.
If you have #include'd "ScoreChart.h" in your "ScoreChart.cpp" file, if in fact you have one, then it's probably a path problem. Another possibility is you haven't add'ed the "ScoreChart.cpp" file to the Solution/Project, or whatever the terminology is with VS2017
cplusplus,
There was no error message from the compiler or linker.
There must have been something corrupted in my project or solution as MS
calls it because I started a whole new one and when I put in my #include it
worked. Then I just cut and pasted all the rest of my code into the new
project. The name of the .cpp is slightly different but that's ok.