I have a struct:
struct something {
int a, b, c, d;
};
Is there some easy way to set all those a,b,c,d into some value without needing to type them separately:
something var = {-1,-1,-1,-1};
Theres still too much repetition (lets imagine the struct has 30 members…)
I’ve heard of “constructs” or something, but i want to set those values into something else in different part of the code.
This is my second answer for this question. The first did as you asked, but as the other commentors pointed out, it’s not the proper way to do things and can get you into trouble down the line if you’re not careful. Instead, here’s how to write some useful constructors for your struct: