delete with 2d array

Started by
13 comments, last by MV 20 years, 6 months ago
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 myArray<A href='http://<b>; myArray[a] = new B(); } </b> ' Target=_Blank>Link</a>
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 .
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 ?
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.
I think you mean std::vector, gentlemen.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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.
Geordi
George D. Filiotis
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.
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]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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
I was merely pointing something out. There''s no need to get your knickers in a twist.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]

This topic is closed to new replies.

Advertisement