I am using a struct from a 3rd party library to pass parameters into library functions.
I wish there were a constructor that would allow me to quickly create a struct, but the library doesn't provide one.
Is there some way to define a constructor outside of the library that I can use within my own code? If not, does anybody else see an elegant solution, here?
My motivation is that I would save some speed because I wouldn't have to construct each struct member twice.
Also, my code would be more readable because I could condense struct creation into one line instead of many lines.
I want to go from this:
Point newPoint;
newPoint.x = someXValue;
newPoint.y = someYValue;
To this:
Point newPoint(someXValue, someYValue);
If you're using C++11, you can construct as:
Point newPoint {someXValue, someYValue};
and if you're not, assuming this is a POD structure, you could:
Point newPoint = {someXValue, someYValue};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With