I am trying to make a data tree that holds multiple data types and vectors. What I have so far is shown below:
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;
}
Now this compiles fine and is exactly what I want, however, if I try to set a value to something like:
int Number = 42;
Chunk[5].LOD[4].Verts[3] = Number;
Then I get the following error:
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'|
So am I missing something or is what I am attempting to do not possible?
Verts[3]is of typeVertStructandNumberis anintso the assignment is not possible (with the posted code). You could specify one of the members ofVertStructas the target of the assignment:If you wanted to be able to assign an
intto aVertStructyou provide anoperator=(int)(as mentioned already by Luchian) but it seems to me it would be quite ambiguous at the call site to what member(s) theintvalue is being assigned to: