I'm trying to load a bunch of information in to a linked list so I don't have to create a ton of class declarations. I want the pointer 'next', that points to the next link, to be null on the last link. I can't seem to accomplish this. I tried it a couple different ways and it either thinks the head link is null, or the link is never ending. If I treat the linked list as a list with only one link (just a head) then all goes well. So any help here would be appreciated.
Code://The beginning portion of my loading function where I think it's having trouble bool LOADOBJ::LoadObjFromFile(char* filename) { std::ifstream file; //create filestream file.open(filename); //open the file for reading if(!file.is_open()) return false; //if the file could not be opened else{ /*first find next available spot in the list*/ ObjectList *temp = GetNextSpace(); //get the next space available temp = new ObjectList; //allocate the space temp->face_count = 0; //set face count temp->vert_per_face.clear(); //set vertices per face temp->next = NULL; //set next link to NULL //....... there's more to this function but its kind of long //the function that finds the end of the link //I tried dynamically allocating here vs. doing it inside the load //function, but it doesn't make a difference ObjectList* LOADOBJ::GetNextSpace() { if(head == NULL){ return head; } else if(head != NULL){ ObjectList *temp = head; while(temp != NULL) temp = temp->next; return temp; } } //and the structure for the linked list struct ObjectList { ObjectList *next; //pointer to next loaded object vector<float> v_x, v_y, v_z; //store x, y, and z components for vertices vector<float> vn_x, vn_y, vn_z; //store x, y, and z components for vertice normals vector<float> vt_x, vt_y, vt_z; //store x, y, and z components for vertice textures vector<int> fv, fvt, fvn; //vertices, vertice textures, vertice normals of each face int face_count; //face count vector<int> vert_per_face; //vertices per face int fvarray[][4]; //face vertex array (not currently used) }; //finally the class class LOADOBJ { private: ObjectList *head; //head ptr in linked list of loaded object files int obj_load_count; //number of loaded object files void Destroy(); //destroys first link in the list ObjectList* GetNextSpace(); //get next available space in the linked list public: LOADOBJ(); //constructor ~LOADOBJ(); //destructor bool LoadObjFromFile(char*); //load object file int GetFileCount(); //get number of object files that have been loaded bool isEmpty(); //determines if the linked list is empty bool RenderAllObjects(); //render all the objects loaded in the linked list }; //end LOADOBJ class



LinkBack URL
About LinkBacks


