问题描述
对于我的一个项目,我真正想要做的是(将其简化到最低限度);
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;
};
我必须承认,我认为不可能直接这样做,在MoveTree中的MoveTree的向量将是verboten。但我试过它反正,它的作品精美。我使用的是Microsoft Visual Studio 2010 Express。
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 ?
I've asked a second question hoping to find a good way of doing this.
推荐答案
C ++标准(2003)清楚地说,实例化一个具有不完全类型的标准容器,调用未定义的行为。
The C++ Standard (2003) clearly says that instantiating a standard container with an incomplete type, invokes undefined-behavior.
在§17.4.3.6/ 2中,
The spec says in §17.4.3.6/2,
__ [..]
- 如果在实例化模板组件时将不完全类型(3.9)用作模板参数。
__ [.. ]
__ [..]
— if an incomplete type (3.9) is used as a template argument when instantiating a template component.
__ [..]
这篇关于C ++递归类型定义是可能的,特别是可以将向量< T>在T的定义内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!