I have multiple C++ projects in a single solution. I have correctly defined the Additional Include Folders... settings for the project which needs to access the files from another project.So I can include the header files defined in another projects without any compilation error.
Now my problem is: Project A has a header file projA.h and its cpp file projA.cpp. The projA.h has some variables in it( and probably in projA.cpp). Now after I am able to include projA.h in projB.cpp(in another project-ProjectB), I would like to access the variables defined in projA.h inside projB.cpp. Will it be possible? If so how?
PS: There are no classes defined in ProjA.h and ProjA.cpp.
// projA.h
#ifndef __PROJA_H_INCLUDED__
#define __PROJA_H_INCLUDED__
externint var;
void func();
#endif
// projA.cpp
#include "projA.h"
int var = 0;
func() {
var += 1;
}
// projB.cpp
#include "projA.h"
#include <iostream>
void doSomething() {
while (var < 100) {
func();
std::cout << var << ' ';
}
}
EDIT:
This is assuming that at least one of these is either a static or dynamic library, so that it can find the variable at linking time. Otherwise, I don't think you can share variables across processes.