編集された答えはコード。
まず、@StoryTellerによってコメントされているように、あなたのベクトルはポインタを格納しています。 - >構文を使用して、それらが指しているオブジェクトにアクセスする必要があります。
構造体が一般的に見られないので、おそらくmyPointsクラスをセットアップするべきです(C++の構造体は、プロパティと関数のデフォルトのアクセス修飾子を除くクラスと同じです)。私はあなたが、単にアクセスし、
上記を残し
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オブジェクトを使用することができますが、いくつかの* myPointsリテラルとVOXを初期化してきたと仮定すると、
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; }
};
のようなものを見て、このクラスを想像します答え、@ 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の使い方は? Vectorごとに1つのPointを保存することができるので、1つの3D配列に3つのPointを持つことができます。 – pospich0815
@ pospich0815、それは賢明な(多分)タグディスパッチの使用を試みています。テンプレートの特殊化は 'getAttribute