편집 된 대답은 암호.
좋아, 먼저 @StoryTeller에 의해 댓글이 달린대로 벡터에 포인터가 저장됩니다. 그래서 당신이 가리키는 객체에 접근하기 위해서는 -> 문법을 사용해야 할 것이다.
구조체가 일반적으로 보이지 않으므로 아마 myPoints 클래스를 설정해야합니다 (C++의 구조체는 해당 속성 및 함수에 대한 기본 액세스 한정자를 제외한 클래스와 동일합니다). 내가
class myPoints // you should probably split this into a header and cpp
{
int tag;
int noOfPoints;
myPoints() : tag(0), noOfPoints(0) // construct with whatever values, you can pass your own
{}
void setNoOfPoints(noOfPoints)
{
this->noOfPoints = noOfPoints;
}
void setTag(tag)
{
this->tag = tag;
}
int getNoOfPoints(){ return noOfPoints; }
int getTag(){ return tag; }
};
당신이 어떤 * myPoints와 복스를 초기화 한 가정처럼 뭔가를 찾기 위해이 클래스를 상상하는 것 당신은 단순히 액세스하고 위의를 떠나
int tag = Vox.at(i).at(j).at(k)->getTag();
int noOfPoints = Vox.at(i).at(j).at(k)->getNoOfPoints();
Vox.at(i).at(j).at(k)->setNoOfPoints(6);
Vox.at(i).at(j).at(k)->setTag(6);
을 다음과 같이 myPoints 개체를 사용할 수 있습니다 리터럴 대답, @ Aconcagua의 답변과 마찬가지로, 나중에 유용하다고 생각할 수도 있습니다.
어쨌든 @StoryTeller가 말했듯이 이미 작성한 코드에서 Voxel 클래스를 사용하여 각 벡터에 대한 noOfPoints 속성을 사용할 수 있습니다. . 복셀 클래스는 다음과 비슷한 모습이 될 것입니다, 단순히 복셀의 인스턴스를 생성, 당신의 벡터에 액세스하고 태그와 noOfPoints을 설정하기 위해 다음과 같이 (헤더를 제공하지 않는 나의 게으름을 용서)
class Voxel
{
private:
vector< vector < vector < myPoints* > > > Vox;
int tag;
int noOfPoints;
public:
Voxel() : tag(0), noOfPoints(0) // construct with whatever values, you can pass your own
{}
vector< vector < vector < myPoints* > > >& getVox(){ return Vox; } //Ignore my shitty naming scheme, you can use this to set or get elements
void setNoOfPoints(noOfPoints)
{
this->noOfPoints = noOfPoints;
}
void setTag(tag)
{
this->tag = tag;
}
int getNoOfPoints(){ return noOfPoints; }
int getTag(){ return tag; }
};
을보고합니다
//A new vector of voxels
vector<Voxel> voxels;
voxels.push_back(Voxel); // this only needs to be a 1d array, you can construct each voxel however you like and add as many as you like
//settting the tag for the first element
voxels[0].setTag(0);
//getting the tag for the first element
int tag = voxels[0].getTag();
// manipulating the contained vector
voxels[0].getVox().at(i).at(j).at(k) = //whatever you are storing in your vector
포인터를 저장하면 "화살표"구문을 사용합니다. Vox [i] [j] [k] -> getAttribute() – StoryTeller
LabelTag 및 NumberOf Points의 용도는 무엇입니까? 벡터 당 하나의 점을 저장할 수 있으므로 한 3D 배열에 3 점이 있습니다. – pospich0815
@ pospich0815, 그것은 태그 디스패치를 영리하게 (아마) 사용하려고 시도합니다. 템플릿 전문화는'getAttribute