-
y1 Redeclared??
I"m having a bit of an issue with variable redeclaration..and frankly i'm quite confused on this one..because the variable in question is in math.h..and i'm not including math.h and to my knowledge neither is any header file that i'm including in my source..
Heres the beginning part of my code:
Code:
#include <iostream>//For use of cout and cin for output and input.
#include <fstream>//For use of ofstream for text file write.
#include <conio.h>//For use of getch() function for keyboard input.
#include <stdlib.h>//For use of exit() function for exiting program.
int x1, x2, x3, x4;
int y1, y2, y3, y4;
Now for some reason I get the error:
int 'y1' redeclared.
:confused: :confused: :confused: :confused: :confused:
-
it is really a really good practice to use the #ifndef and #define pair when including multiple header files...it keeps these kind-of problems from coming up.
-
Show the rest of the code and the exact error. Most compilers tells the line where a variable is beeing redeclared!
Or you could use extern if these variables are in a header file...
-
>it is really a really good practice to use the #ifndef and #define pair when including multiple header files...it keeps these kind-of problems from coming up.
Could you provide an example?
>Show the rest of the code and the exact error. Most compilers tells the line where a variable is beeing redeclared!
As far as what line it is, the line was:
Code:
int y1, y2, y3, y4;
And no I didn't declare it twice in this particular source..I only have one source file. That line was right after the #include preprocessor directives, there global variables so..
I'll try my best to recover the code(I'm recoding it right now...kind of a hassle, but I had to reinstall windows on this machine and fast..).
>Or you could use extern if these variables are in a header file...
I'm assuming that there in a header file, but i'm not quite sure. But in any case could you provide an example of this as well?
-
To ue global variables in multiple source files, you do this way:
Code:
//code.h
extern int myInt;
Code:
//code1.cpp
#include "code.h"
int myInt;
//use int where you want
Code:
//code2.cpp
#include "code.h"
//use int where you want
-