Consider the code related to a previous SO question C++ cyclic dependency confusion with adjacency list representation
#include
#include
It is undefined behavior to instantiate a standard library container with an incomplete type. [res.on.functions]/1, 2.5:
1 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.
2 In particular, the effects are undefined in the following cases:
- [...]
- if an incomplete type (3.9) is used as a template argument when instantiating a template component, unless specifically allowed for that component.
Both implementations are correct.
There is currently a proposal to add incomplete type support to some containers, but it is limited to vector
, list
and forward_list
.