Re[4]: std::variant для вложенного класса
От: sergii.p  
Дата: 04.12.25 14:17
Оценка: 10 (1) +2
Здравствуйте, rg45, Вы писали:

R>Ну, в таком случае очень хотелось бы найти объяснение.


R>Выглядит очень странно: вынос структуры наружу или отказ от инициализации мембера устраняют ошибку. Кто-нибудь видит связь или логику? Я — нет.


типа в этом случае вложенный класс считается неполным до завершения объявления внешнего

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88165

This declares a default constructor that might be defined implicitly by the compiler, **or** it might get deleted if the member definitions of D would make the implicit default constructor ill-formed. This is obviously very different from the case where you declare B(); There is no assertion that D is default constructible, the compiler has to deduce whether or not that's true. That depends on the default member initializer for D::i. The initializer (which is just '0' here) is a "complete class context" which means it is not processed until the class D is complete (this allows you to use other members, or e.g. sizeof(D) as the initializer).

A nested class like C::D is not complete until its enclosing class is complete. This means the initializer for C::D::i is compiled after C is complete. This means whether C::D is default constructible is not known until C is complete.

 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.