I'm trying to make a general variable which I can use in all functions using Structs.
But one void also does hold variables which should be used multiple times.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
struct out {
int result;
};
void test(int x, int y) {
out in;
in.result = x + y;
}
int main() {
out test;
test(5, 11);
cout << test.result;
}
On line 9 the test() function should return a value.
On line 15 you are declaring a variable with the same name as a function, this is illegal.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
struct out {
int result;
};
void test(int x, int y) {
out in;
in.result = x + y;
}
int main() {
out t;
t = test(5, 11);
cout << test.result;
}