A static variable has a file size. Say I have the following two files:
- file1.h
- file1.cpp
- file2.h
- file2.cpp
I declared a static variable say static int Var1 in both header files. Both file1.h and file2.h are included in the main.cpp file.
I did this because the static variable will have a file area, so it will not conflict with each other. But after compilation, I found that it shows a conflict.
Now the static variable behaves like an extern variable. On the other hand, if I declare a static variable in both .cpp files, it compiles well.
I can not understand this behavior.
Can any body explain how area and communication work in this scenario.
Chris_vr
source share