Archived

This topic is now archived and is closed to further replies.

cybo

help with a linked list class please

Recommended Posts

I need to insert nodes in a sorted order....and for some reason: ....here is the code where Im getting trouble Im getting an acess violation Node * getLink(); //.h Node * Node::getLink() //.cpp { return link; } link is defined as Node * link; in the .h of the node file

Share this post


Link to post
Share on other sites
Why would you post this in the lounge?

That''s not nearly enough information to answer the question; there''s a linked list tutorial here on the site, I believe, and even if there''s not a little searching will uncover one. Its a common enough problem.

PS: ''ASSERT(link);'' before using it

CM

Share this post


Link to post
Share on other sites
That's probably not what's giving you the error. Returning a memory address is completely harmless.

It's what you're trying to DO to that memory address that's giving the error.

What's calling that function when the error occurs?
What happens to that pointer value after it returns?

You need to do a lot better logging if you want to do dynamic memory. Otherwise you're going to spend a lot of time chasing red herrings.

Try using cout<<link->getLink()+0<
You may be trying to write to a NULL pointer. That will show you the address it's returning. The +0 turns it into an int. Probably isn't needed.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]


[edited by - KalvinB on November 3, 2002 6:20:35 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Yann L
-> this should be in the general programming forum.

This was already here
cybo, cross-posting is bad.. (unless, of course, he did it because people asked him to ). I'll try to come up with something wiser to say once you give more info

C++: Boost | GOTW tips | GOTW articles | FAQ lite | CUJ

[edited by - Hanz on November 3, 2002 7:24:47 PM]

Share this post


Link to post
Share on other sites
quote:

This was already here


Right. I didn''t check for doubles before moving. Since this post doesn''t contain any relevant information needed to solve the problem (class structure, member function code, etc), and since it''s redundant, I''m closing it. Further discussion please in his first thread.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.