Код: Выделить всё
union U {
int a;
double b;
};
static constexpr inline auto a_ptr = &U::a;
static constexpr inline auto b_ptr = &U::b;
static constexpr inline U u1 = U{}; // fine
static constexpr inline U u2 = U{.b = 1.0 }; // fine in this example, but only works if U is aggregate, need something else
static constexpr inline U u3 = U{.*b_ptr = 1.0 }; // syntax error
< /code>
Это не может компилироваться с синтаксической ошибкой. Та же проблема возникает, когда я пытаюсь то же самое со структурой.union U {
constexpr inline ~U() {
// assume memory leak handled external
}
int a;
double b;
std::string c;
};
static constexpr inline U u = U{.c = "lorem ipsum" };
Подробнее здесь: https://stackoverflow.com/questions/794 ... s-possible