Jan 26, 2009 at 6:47pm UTC
In Microsoft Visual Express you can have more than one source file in a project, but how can i make it so that I have functions spread between them.
IE:
main.cpp
global declarations
int main()
other.cpp
void other()
void another()
Jan 26, 2009 at 7:01pm UTC
Use a header file to store the function prototypes.
Jan 26, 2009 at 7:14pm UTC
sorry, but how would I do that?
at the moment I have something like:
header.h
void other()
void another()
main.cpp
#include "header.h"
int main()
other.cpp
#include "header.h"
void other()
void another()
but it says that the variables that are defined in main.cpp are "undeclared identifiers", would I have to define them in header.h somehow?
Jan 26, 2009 at 7:45pm UTC
You would need to declare i outside the function in the Header.cpp - not outside main.cpp
or
main.cpp
1 2 3 4 5 6
#include "Header.h"
int i = 5;
int main() {
other(i);
return 0;
}
header.cpp
1 2 3 4 5 6 7 8 9
#include "Header.h"
void other(int temp) {
temp ++;
}
void another(int temp) {
cout << 55 * temp
}
EDIT
header.h
1 2 3 4 5 6 7
#ifndef HEADER_H_
#define HEADER_H_
void other(int temp);
void another(int temp);
#endif
Sorry forgot to add the header.h
Last edited on Jan 26, 2009 at 7:54pm UTC