我需要访问一个矢量指针元素,我的动画结构有以下代码(这里简化,不必要的变量被切断):
struct framestruct {
int w,h;
};
struct animstruct {
vector<framestruct> *frames;
};
vector<framestruct> some_animation; // this will be initialized with some frames data elsewhere.
animstruct test; // in this struct we save the pointer to those frames.
void init_anim(){
test.frames = (vector<framestruct> *)&some_animation; // take pointer.
}
void test_anim(){
test.frames[0].w; // error C2039: 'w' : is not a member of 'std::vector<_Ty>'
}
该阵列有效,我通过以下方式对其进行了测试:
test.frames->size()
它是我计划的 7。
那么如何从向量中访问第 N 个索引处的向量元素(w 和 h)?