Jump to content
  • Advertisement
Sign in to follow this  
drkpriest

Memory Management Error

This topic is 5135 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

*edit* sorry it wouldn't accept my post for some reason. it is pretty big i suppose. you can get it here: http://www.geocities.com/dr_xorsysm/post.txt [Edited by - drkpriest on September 3, 2004 12:47:08 AM]

Share this post


Link to post
Share on other sites
Advertisement
looks a bit that way ay.. it has to be the [] operator changing the array pointer and not the value. hmm just frustrating. oh well stl it is :P i didn't really want to succumb to its evilness. i'm just one of those people that like to know how everything works. but anyways..

Share this post


Link to post
Share on other sites

type* operator [](int index)
{

// make sure a valid index is specified
assert(index => 0 && index < arraySize);

return (array[index]);
}



Shouldn't it be "return &array[index]"?

Did you really debug this code? I think you didn't since the expression inside the assert wouldn't compile (=> should be >=)

Share this post


Link to post
Share on other sites
Yes your subscript operator signature is syntactically correct but is schematically wrong.

For one there should be two subcript operators one that is constant & another non-constant member functions and they should return constant & non-constant references not pointers.

Further more you shouldn't use ints for indexing, prefer using standard library size_t type defined in cstddef header, so with all that in mind it should be of the form:


#include <cstddef>

typedef size_t size_type;

const type& operator [](size_type index) const {

// make sure a valid index is specified
assert(index >= 0 && index < arraySize);

return array[index];

}

type& operator [](size_type index) {

// make sure a valid index is specified
assert(index >= 0 && index < arraySize);

return array[index];

}





really thou your just writing an inefficient version of the standard library container vector so i would recommend you use that instead.

Share this post


Link to post
Share on other sites
thanx for the help guys. its still crashing tho. i originally had type& return value for the subscript operator but pasted it in as type* as i forgot to change it back from previous tests. i debugged it and found that the delete statement in the static removeAllObjects() method was trying to delete an invalid pointer. I cant see why it is doing that tho..

doho: was just a typo when i posted it. its <= in my code. thanx for that tho.

*edit*

snk_kid: yeah rewriting it now with containers. :)

Share this post


Link to post
Share on other sites
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!