Are C++ recursive type definitions possible, in particular can I put a vector within the definition of T?

前端 未结 6 2135
轻奢々
轻奢々 2020-11-27 21:32

For one of my projects, what I really wanted to do was this (simplifying it to the bare minimum);

struct Move
{
    int src;
    int dst;
};

struct MoveTree         


        
6条回答
  •  伪装坚强ぢ
    2020-11-27 21:52

    Use a pointer to the type in the Vector, this will be portable.

    struct Move
        {
            int src;
            int dst;
        };
    
    struct MoveTree;
    
    struct MoveTree
        {
            Move move;
            std::vector variation;
        };
    

提交回复
热议问题