Voids, structs, and main

Hello

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>

using namespace 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;
}
            


How can I do this?

Thanks for reading,
Niely
But one void also does hold variables which should be used multiple times.

Can u explain what you really mean?
But one void also does hold variables which should be used multiple times.
http://msdn.microsoft.com/en-us/library/fxky5d0w.aspx

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>

using namespace 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;
}
Last edited on
Thanks! :)
It's fixed now.
Topic archived. No new replies allowed.