class (or struct) self-reference by template

前端 未结 1 635
执念已碎
执念已碎 2020-12-19 02:25

Is the following legal?

template< typename T >
struct tree_node
   {
   T t;
   std::vector children;
   };

A commen

1条回答
  •  自闭症患者
    2020-12-19 03:12

    Actually, as a result of N4371 we have (from N4527, [vector.overview], will be in C++17):

    An incomplete type T may be used when instantiating vector if the allocator satisfies the allocator completeness requirements 17.6.3.5.1. T shall be complete before any member of the resulting specialization of vector is referenced.

    Prior to this, vector could not be constructed with an incomplete type (which tree_node is at that point), and that would be undefined behavior.

    0 讨论(0)
提交回复
热议问题