なぜこれが私にセグメンテーション違反を与えるのか誰かが知っていますか?
cell.h
struct cell{
bool filled;
bool isParent;
//float px,py,pz,s;
bool cx,cy,cz;
unsigned char r,g,b;
vect norm;
struct cell* parent;
struct cell* child;
cell(bool cxx=0, bool cyy=0, bool czz=0);
void open_read(string);
};
cell.cpp
cell::cell(bool cxx, bool cyy, bool czz)
{
cell childs[8]; // these lines creates a segmentation fault
child = &childs[0]; // these lines creates a segmentation fault
cx=cxx;
cy=cyy;
cz=czz;
norm = vect(0,0,0);
norm.normalize();
isParent=false;
filled=true;
}
これが間違った方法である場合、メモリを大量に消費するため、8個のポインタを格納する代わりに、child[8]の最初の要素への単一のポインタを格納する方法について誰かが正しい方向に向けることができます。