structure declaration

Mar 8, 2010 at 2:12pm
hi im new to C++ and got stuck on some parts of assingment which i seek help :)
say i have structure. The output is 0. Is there a way to change structure variables inside mothod/function? this is simple version of the actual code.
thanks for any help in advance. :)

1
2
3
4
5
6
7
8
9
10
11
12
struct Bag {
	double coppers;
} Bag1;

void test (Bag bagNum , double number){
     bagNum.coppers = number;
}

int main {
     test(Bag1, 5);
     cout<<Bag1.coppers<<endl;
}
Last edited on Mar 8, 2010 at 2:20pm
Mar 8, 2010 at 2:23pm
Firstly, main is a function, so you have to include parentheses: int main()

And now to your problem: You have to pass the first argument as a reference:

void test (Bag & bagNum, double number)
Mar 8, 2010 at 2:32pm
OMG that worked. thanks for help didn know it was that simple.
Topic archived. No new replies allowed.