about pre-compile #include directive


main.cpp
1
2
3
  #include "one.h";
  #include "two.h";
  ...


there are other files:
one.h
one.cpp
two.h
two.cpp

if there is a variable defined in one.cpp
 
  int a;

and declared in one.h
 
  extern int a;


and there is a varialbe defined in two.cpp
 
  int b;

but the variable b is not declared in two.h

then, I think a is a global variable in main.cpp
b is a global variable in two.cpp but not visible in main.cpp
if I want a to be a global variable in two.cpp, what should I do?
thank you!
I would answer, but it really sounds like you are rephrasing a homework question. At least you didn't simply copy and paste...

I would compare the two syntaxes you have been given and see what the differences are, then look up what that difference does for you.
no, I'm just puzzled by such stuff
I elaborated the question in such a way in order to make it clear to everyone who want to give a hand
thank u!
Last edited on
If you try to compile it you should have linker errors.
All the source files are linked so it will result that 'b' was defined twice
Topic archived. No new replies allowed.