I have a struct that I initialize like this:
typedef struct
{
word w;
long v;
}
MyStruct;
MyStruct sx = {0,0};
Update(sx);
Now, it seems such a waste to first declare it and then to pass it. I know that in C#, there’s a way to do everything in one line. Is there any possiblity of passing it in a more clever (read: cleaner) way to my update function?
It depends on how your
Updateis declared. If it expects a value ofMyStructtype or a reference ofconst MyStruct&type, you can just doThis is possible because you wanted to initialize your object with zeroes (which is what the
()initializer will do in this case). If you needed different (non-zero) initializer values, you have to either provide a constructor forMyStructor do it the way you do it in your question (at least in the current version of the C++ language).