1
我有一种类型是这样的:向类型::成员的数组类型的向量?
class Foo {
public:
int bar[3];
/*Possibly some other members in here*/
};
什么是获得一个std:vector<Foo>
到int
阵列的有效途径?该阵列应该是bar
载体的Foos
的顺序映射。
这够了吗?
int* array = new int[foos.size() * 3];
int offset = 0;
BOOST_FOREACH(Foo& f, foos) {
memcpy(array + offset, f.bar, sizeof(int) * 3);
offset += sizeof(int) * 3;
}
或者还有更好的方法吗?
我很困惑...你要求得到一个向量,但是你使用`:: operator new`来分配一个数组? – 2010-12-10 00:45:14