e.g.
#include <iostream>
using namespace std;
struct Point {
int x;
int y;
};
int main() {
Point p1 {1};
Point p2 {.y=2};
cout << p1.x << ", " << p1.y << endl;
cout << p2.x << ", " << p2.y << endl;
return 0;
}
Is there any way to force the caller to initialize all struct members when using initializer lists? I want to ensure both x
and y
are set by the caller in this example.
I also want to allow designated initializers. Many of our structs are very long and that syntax adds much-needed clarity.