0
When are they useful?
When is using structures useful in c++?
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;
}
+ 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!
0
@Zeke Williams I see now, thank you I haven't got to classes yet so I was just wondering