help with a linked list class please

Started by
5 comments, last by cybo 21 years, 5 months ago
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
Paranoid Lunatic with a heart of gold
Advertisement
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
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]
Make sure link has a value and memory has been allocated for it.
Did you forget to say:
link = new node();
-> this should be in the general programming forum.

Besides that, you need to provide a lot more information about your class structure and code.
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]
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.

This topic is closed to new replies.

Advertisement