Jump to content
  • Advertisement
Sign in to follow this  
MattHughes

Elementary Linked List crashing (C++) [RESOLVED]

This topic is 3938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, The addFace(..) method causes this simple linked list to crash. I haven't a clue why, but I've narrowed it down to line 21: (*last).next = &f; (to clarify, this compiles, but crashes at runtime) #include <iostream> using namespace std; class Face {}; class FaceNode { public: Face f; FaceNode *next; FaceNode() {}; FaceNode(Face _f) { f = _f; } }; class FaceList { public: FaceNode *first, *last; void add(FaceNode f) { //make the pointer in the current tail point to the new node (*last).next = &f; //---CRASHES HERE------------ //now the tail points to the new facenode last = &f; } FaceNode getFirst() { return *first; } }; class Model { public: FaceList faces; void addFace(Face f) { FaceNode fn(f); faces.add(fn); } }; int main() { Model m; Face face; m.addFace(face); // causes program to crash cout << "hello, world" << endl; system("PAUSE"); return 0; } Any ideas of why this is happening? Thanks in advance [Edited by - MattHughes on November 4, 2007 10:23:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!