我試圖製作一個保存多種數據類型和向量的數據樹。我至今如下所示:C++中的向量和結構
struct VertStruct{
double X, Y, Z;
};
struct FaceStruct{
int F1, F2, F3, F4;
};
struct FaceNormalStruct{
double X, Y, Z;
};
struct LODStruct{
std::vector<VertStruct> Verts;
std::vector<FaceStruct> Faces;
std::vector<FaceNormalStruct> FaceNormals;
};
struct ChunkStruct{
std::vector<LODStruct> LOD;
};
int main(){
std::vector<ChunkStruct> Chunk;
Chunk.resize(100);
for(int i = 0; i < 100; i++)
{
Chunk[i].LOD.resize(5);
for(int j = 0; j < 5; j++)
{
Chunk[i].LOD[j].Verts.resize(36);
Chunk[i].LOD[j].Faces.resize(25);
Chunk[i].LOD[j].FaceNormals.resize(25);
}
}
return 1;
}
現在這個編譯很好,正是我想要的,但是,如果我嘗試將值設置爲一樣的東西:
int Number = 42;
Chunk[5].LOD[4].Verts[3] = Number;
然後我得到出現以下錯誤:
main.cpp|126|error: no match for 'operator=' in 'Chunk.std::vector<_Tp, _Alloc>::operator[] [with _Tp = ChunkStruct, _Alloc = std::allocator<ChunkStruct>](5u)->ChunkStruct::LOD.std::vector<_Tp, _Alloc>::operator[] [with _Tp = LODStruct, _Alloc = std::allocator<LODStruct>](4u)->LODStruct::Verts.std::vector<_Tp, _Alloc>::operator[] [with _Tp = VertStruct, _Alloc = std::allocator<VertStruct>](3u) = Number'|
所以我錯過了什麼或者是我試圖做不到的事情?
我知道這是簡單的東西我很想念,謝謝你指出:) – LucasS