class SomeClass
{
SMesh Mesh;
SMeshBuffer MeshBuffer[3];
public:
SomeClass()
{
Mesh = SMesh();
for(int i=0; i<3; i++)
{
MeshBuffer[i] = SMeshBuffer();
Mesh.addMeshBuffer(&MeshBuffer[i]);
// Will this cause any problem when ~SMesh() is called?
}
}
~SomeClass()
{
// Should I do something here?
}
};
Or should I new mesh and mesh buffers to avoid the trouble?
What hybrid said. Furthermore, in your deconstuctor (~SomeClass() ), you can call "Mesh->drop()" (which handles deletion), but for your usage, it looks like "delete Mesh" would work.
Yeah, but once you gave the pointer to the mesh somewhere else, it might be grabbed by the external entity. So always do drop() for classe based on IReferenceCounted. And also make sure that you call drop on the meshbuffers right after you called addMeshBuffer. This will ensure that onyly the SMesh holds a reference (and not the surrounding class) and thus everything wil be cleaned up properly.