I created a class Something which holds a member variable.
I am able to do this, which works as intended:
struct Something
{
bool Works;
};
int main()
{
Something s = {
.Works = false,
};
}
Now, I want to created a struct inherited from Something, named Something2, and want to do the same thing, but I want to be able to have access to Something::Works (which I renamed DoesntWork, since it doesn't work!):
struct Something
{
bool DoesntWork;
};
struct Something2 : public Something
{
bool Works;
};
int main()
{
Something2 s2 = {
.Works = true,
.DoesntWork = false,
};
}
https://godbolt.org/z/rYT3br467
I am not looking for an alternative, I can already think of some. I am only wondering if this is possible, and if yes then how.
If it is not possible, I would really like to know the low-level reason, so don't hesitate!
UPDATE: Thanks to Nathan Oliver's comment, you can read: Designated initializers in C++20