I need to be able to do this; I've got two files:
A: The file which configure variables in B. A always stays on same PC.
B: This file should be able to be used separated (other PC, other network,...) and includes some variables.
Of course those two are compiled CPP-files (.exe).
So, file B is dynamic; file B has variables, in this example y, and x.
A needs to be able to define y and x, but remember that B should work when A is on another PC.
Pseudo code:
A)
1 2 3
cross_file int a, b;
int a = 5;
int b = 7;
B)
1 2 3 4 5
cross_file int x, y;
x = file_A(a);
y = file_A(b);
cout << x + y <<endl;
RESULT: 12
Any way to do this?
I've already heard of 'extern', but I think that for this A and B should always stay together.
It does sound like you want to have two processes and one process should connect to the other over network for data transfer. A client and server. Just like a browser process sends a string (url) to http server and the server returns a string (html content) to the browser. Or a database and its client. (The latter might be closer to your case; client B queries values from database A.)
@keskiverto:
No, the two C++ files (A & B) shouldn't be interacting at all any more.
You configure (the variables) of B using A on computer named Alpha.
Then you send B to another computer so it can do what it should do regarding the variables.
So, once B goes to computer Beta; A on computer Alpha lost all control over it and they ain't interacting any more.
With other words, one the variables in B are defined (and saved) you can't change them after that.
In other words you do compile program "B" and give it for others to use.
What is wrong with:
1 2 3 4 5
int x, y;
x = 5;
y = 7;
cout << x + y <<endl;
RESULT: 12
The const literal values are in written into the binary of B during the compilation of B in Alpha.
If you have to compile the B in Beta, then you have to send the sources of B to Beta and along them the lines that set the variables and the person compiling in Beta can modify the source of B, values included. You could precompile (the A) part of B into object files so that in Beta you merely link them to the rest of B. Is that what you are asking?
But when I share my application (A), so that other user called Gamma can also generate the file B.
How can I let A compile B then? What if the user doesn't have a compiler installed at all?