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

Viewed 6487

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
{
    Move move;
    std::vector<MoveTree> variation;
};

I must admit that I assumed that it wouldn't be possible to do this directly, I thought a vector of MoveTree s within a MoveTree would be verboten. But I tried it anyway, and it works beautifully. I am using Microsoft Visual Studio 2010 Express.

Is this portable ? Is it good practise ? Do I have anything to worry about ?

Edit: I've asked a second question hoping to find a good way of doing this.

6 Answers
Related