Hi
I am working with multiple files in my program, and I have really confused myself. I have tried condensing my problem for this question. First an overview of the 4 files in the program:
My main.cpp is
Code:
#include <iostream>
#include <vector>
#include "constants.h"
#include "ext1.h"
using namespace std;
int main() {
vector<double> temp;
vector<double>::iterator i;
ext_func();
return 0;
}
There is one external file "ext1.cpp". The variable b must only be visible to functions within "ext1.cpp", but all other variables declared in "main.cpp" it should have access to.
Code:
#include <iostream>
#include <vector>
#include "constants.h"
int b = 2; // this must only be visible to ext1.cpp
int ext_func() {
i = temp.begin();
cout << *i << endl;
}
The header for "ext1.cpp", "ext1.h"
Code:
#ifndef EXT1_H
#define EXT1_H
int ext_func();
#endif
The final header "constants.h", which is visible to both .cpp-files
Code:
#ifndef CONSTANTS_H
#define CONSTANTS_H
const int a = 2;
#endif
My program does not compile. There is an error "1 unresolved externals". Can I get a hint to the error? Besides that I am not sure that the scope for the different variables is as I have intended, but once I can compile, I will be able to test it out.
Thanks for the help in advance.
Best,
Niles.