всем привет. Пишу так
struct B
{
std::unordered_map<int, B> childs;
};
не компилируется (/usr/include/c++/6/bits/stl_pair.h:211:11: error: ‘std::pair<_T1, _T2>::second’ has incomplete type)
переписываю на
struct B
{
std::map<int, B> childs;
};
всё нормально. Кто-то может объяснить почему?
microsoft компилирует оба варианта. Это gcc так выделывается.
Здравствуйте, sergii.p, Вы писали:
SP>всё нормально. Кто-то может объяснить почему?
Потому что нет требования стандарта это компилировать.
Отдано на откуп реализации.
https://stackoverflow.com/a/13089641
17.6.4.8:
In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.
In particular, the effects are undefined in the following cases:
...
if an incomplete type is used as a template argument when instantiating a template component, unless specifically allowed for that component.
SP>microsoft компилирует оба варианта. Это gcc так выделывается.
Судя по всему GCC в обозримом будущем и не будет компилировать.