0

When are they useful?

When is using structures useful in c++?

18th Jul 2017, 7:08 PM
Chris
Chris - avatar
3 Respostas
+ 2
@Chris, you are welcome! Just in case you wanted to know how to use this, since you said you haven't gotten to classes yet, it's pretty straight foward: //what I typed before int main() { AB answer; answer = func(); cout << answer.a << ", " << answer.b << endl; return 0; }
19th Jul 2017, 12:41 AM
Zeke Williams
Zeke Williams - avatar
+ 1
Structures can be very useful in code. For example, maybe I need to return more than one value from a function; I can do this using a structure: struct AB { int a; int b; }; AB func() { AB object; object.a = 11; object.b = 5; return object; } They are the same thing as a class, but they are public by default. A class is private by default. Hope this helps - happy coding!
19th Jul 2017, 12:35 AM
Zeke Williams
Zeke Williams - avatar
0
@Zeke Williams I see now, thank you I haven't got to classes yet so I was just wondering
19th Jul 2017, 12:38 AM
Chris
Chris - avatar