Original Post
Hi! I'm having a rather nasty time trying to get my nested classes working together with stl. As soon as I've executed the code below and the function that called the push_back is finished, the program hangs. Is there something wrong with how I'm adding the objects to the lists, etc? If I skip the Model = new model(..) part, things works just fine... why is that? Baseobject class (bo): and finally, the model class: I would be truly grateful for any help you can provide, since I'm having a hard time visualizing the problem in this case... It could be that the push_back's are performed locally and trown away when the Add-function is ended... but that doesn't explain the freezing of the program, does it? Once again, thanks for your time and help! /Robert [Edited by - Rasmadrak on December 29, 2006 3:05:20 PM]
//Program hangs after calling this function:
void Add(char *file, vec pos)
{
bo test("e:\\tes.lwd");
test.pos = pos;
Objects.push_back(test);
}
class bo
{
// variables: ------------------------------------------------------------------
public:
//extra stuff removed, since it's not relevant for this issue.
model *Model;
// constructor / destructor: --------------------------------------------------
bo(char *file="")
{
Model = NULL;
if (std::strcmp(file,"")!=0)
{
Model = new model(file);
}
};
};
struct vertex
{
float x,y,z;
};
struct object
{
list<vertex> Vertex;
};
struct group
{
bool Blended;
vector<int> Texture;
list<object> Objects;
};
class model
{
public:
bool Loaded;
char *name;
list<group> Group;
model(char *file)
{
Loaded=false;
name = file;
//try to load "file".
// for (each texture)
{
group thisgroup;
int thistexture = SetTexture(x);
thisgroup.Texture.push_back(thistexture);
for (int a = 0; a < objectcount; a++) { //nr of objects
object thisobject;
for (int b = 0; b < vertexcount; b++) { //nr of vertices
vertex V;
inFile >> V.x >> V.y >> V.z;
thisobject.Vertex.push_back(V);
}
thisgroup.Objects.push_back(thisobject);
}
Group.push_back(thisgroup);
}
Loaded=true;
}
};