Unlike claims in other answers, it is really not legal to instantiate any standard container, including std::list , with an incomplete type. (For a language-lawyer discussion of this, see for example, How can I use an incomplete type as a template parameter for a vector here? )
This requirement is only relaxed in C ++ 17 for std::forward_list , std::list and std::vector . For any earlier standard, source code that works with newer versions of VC and gcc is a non-standard extension. This also applies to your observations with std::vector .
In pre-C ++ 17, for portability of std::list some class T as a member of the specified class, you will need a workaround, for example std::list<T*> , or use the boost.container library, which already implements the easy-to-use requirements portable.
Note that even in C ++ 17 you can create an instance of the class template itself with an incomplete type. The type must be completed when any element is created.
Baum mit augen
source share