我对使用
例如:
所以,问题是:在 for 循环结束时,
我希望我解释清楚了我的疑惑。 感谢您的时间。
std::vector
有疑问。
如果我有一个结构体,其中包含一个在内存中未定义空间的std::vector
对象,如果需要重新分配(std::vector
),那么这个结构体是否也会被重新分配?还是只有std::vector
会被重新分配?例如:
struct cluster{
int a;
int b;
struct cluster* parent;
vector<struct cluster> children;
}
struct cluster obj = {2,1,...};
struct cluster *pobj = &obj;
for(int i = 0; i < 100 ; i ++){
children.push_back(i); //The capacity will be increased progressly, no?
}
所以,问题是:在 for 循环结束时,
pobj==&obj
吗?还是因为子 std::vector
对象的重新分配而重新分配 obj
?我希望我解释清楚了我的疑惑。 感谢您的时间。
childs
时,cluster
是一个不完整的类型,你不能用它来实例化std::vector
。 - juanchopanzastruct
,只需要在定义类时使用即可。(另外,在英语中,“child”的复数形式是“children”,而不是“childs”。英语甚至比 C++ 更不连贯。) - James Kanzeboost::container
的不完整类型容器。其中有一个vector
类,允许你进行嵌套操作。 - juanchopanza