Код: Выделить всё
#include
#include
struct A {
int const n;
void f() {
new (this) A{2};
}
void g() {
std::cout n;
}
void h() {
std::cout n;
}
};
int main() {
auto a = A{1};
a.f();
std::cout n; // This is guaranteed to print 2.
a.h(); // This is guaranteed to print 2.
a.g(); // Is it guaranteed to print 2?
std::cout
Компилятор разрешается предположить, что действительно константная переменная (не
просто констант, но переменная объекта, объявленная const).std::cout n;C ++ 23 Гарантия std :: cout n; p n; p n; a eake aeave ue ves ude ra std :: raund std> std :: rhound> n;>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -scenarios
Мобильная версия