我有一个关于查找 2D 矢量大小的问题。我的简单问题是我有一个向量,其中存储三个“形状”,每个形状都有随机数量的命中点(存储为笛卡尔坐标 {x,y,z})并且每个命中点都有随机颜色(存储为 RGB)我想知道每个形状有多少生命值。如果我做:
VectorOfShapes.size()
我得到答案
3
这是在此处之前提出的类似问题 。但这对我没有帮助。他们的解决方案是
VectorOfShapes[1].size()
我试过了,我得到了以下错误“错误C2228:'.size'的左边必须有类/结构/联合 ”。答案很好(点击链接)。它仍然没有帮助我(或者我很愚蠢)......有什么想法吗?
//---------添加信息
class World {
public:
vector<Flux*> VectorOfShapes;
void
containers(int obnum, Ray reflect, RGBColor Ll);
void
build(void);
void
add_vectorshape(Flux* vectorshape_ptr)
private:
void
delete_VectorOfShapes
}
inline void
World::add_vectorshape(Flux* vectorshape_ptr){
VectorOfShapes.push_back(vectorshape_ptr);
}
void
World::containers(int obnum, Ray reflect, RGBColor Ll)
{
vectorOfShapes[obnum]->push(reflect);
VectorOfShapes[obnum]->push(Ll);
int sizers = VectorOfShapes[0].size(); //this is where the code is giving me errors
}
void
World::build(void) {
Flux* vectorshape_ptr1 = new Flux;
add_vectorshape(vectorshape_ptr1);
Flux* vectorshape_ptr2 = new Flux;
add_vectorshape(vectorshape_ptr2);
Flux* vectorshape_ptr3 = new Flux;
add_vectorshape(vectorshape_ptr3);
}
void
World::delete_VectorOfShapes(void) {
int num_VectorOfShapes = VectorOfShapes.size();
for (int j = 0; j < num_VectorOfShapes; j++) {
delete VectorOfShapes[j];
VectorOfShapes[j] = NULL;
}
VectorOfShapes.erase (VectorOfShapes.begin(), VectorOfShapes.end());
}
class Flux{
public:
std::vector<Ray> rays;
std::vector<RGBColor> L;
void push(Ray ray);
void push(RGBColor Ls) ;
};
inline void
Flux::push(Ray ray) {
rays.push_back(ray);
}
inline void
Flux::push(RGBColor Ls){
L.push_back(Ls);
}