Jump to content
  • Advertisement

Archived

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

MV

delete with 2d array

This topic is 5469 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, I''ve got troubles using "massive" delete(s) ; I''ve got a 2d array containing POINTERS to some Vertex (my class name) objects. I try to delete a part of the array and then to replace each erased Vertex with a new DVertex (DVertex is derivated from the Vertex object). I''ve got an "access violation" occuring at random position (I think it''s random but I''m not sur) While debugging using VC6, the call stack contains -- Vertex::''scalar deleting destructor''unsigned int -- before the destructor. Dont know what it is... Questions : - "massive" deletes are ok ? - replace a pointer with a pointer of an derivated object is ok ? I post no code, cause my project starts to be very big ! It look''s like : class A {...}; class B : public A {...}; A *myArray[10][10]; for (a = 4 ; a < 6 ; a++) for (b = 4 ; b < 6 ; b++) { delete myArrayLink

Share this post


Link to post
Share on other sites
Advertisement
Oh, the bliss of using STL::vector (and boost::shared_ptr) has caused me to forget the pain of this kind of delete...
Anyway if you are sure this is the way you want to go I suggest you declare a type (which will make everything much easier):

typedef A * APtr;

APtr myArray[10][10];

for(a = first; a < last; ++a)
{
for(b = first; b < last; ++b)
{
delete myArray[a][b];
myArray[a][b] = new B;
}
}

But I still recommend you at least switch to using STL::vector, it''s so much more convenient .

Share this post


Link to post
Share on other sites
The thing is that I use STL::vector ! :D
Actually it''s a bit complexe, so I simplified the description. I use both 2d array and stl vector.

I cant see what the typedef changes ?!

Replace an object by a derivated one isn''t a problem ?

Share this post


Link to post
Share on other sites
Maybe if you post a snippet of your real code it would be easier to help you. Maybe what you think is the problem isn''t the problem at all.
A typedef changes the clarity of the code. I always use it in multi-dimensional arrays so it''s clear to me (and others) what is stored at each index.

Share this post


Link to post
Share on other sites
An access violation means you tried to delete a pointer which wasn''t pointing to anything useful. Check your initialization code to make sure that you initialize correctly.

George D. Filiotis

I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites
quote:

I think you mean std::vector, gentlemen.


Yeah, thanks for the tip, but we already know. std is the namespace all C++ standard library should be in (even the old C standard lib). STL is a subspace of std, the Standard Template Library. It''s not a namespace, but a concept. But thank you for participating.

Share this post


Link to post
Share on other sites
quote:
Original post by amag
Yeah, thanks for the tip, but we already know.


Yes, that's why where you writing "STL::vector"...
quote:
Original post by amag
STL is a subspace of std, the Standard Template Library. It's not a namespace, but a concept. But thank you for participating.


You don't need to explain anything to me, dear.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on October 25, 2003 9:38:38 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

You don''t need to explain anything to me, dear.


No, obviously it wouldn''t help.
I think you would win on cutting down on the bessewisser-crap. Thanks for another useful post.
/amag

Share this post


Link to post
Share on other sites

  • 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!