use array or vector

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

I need to use arrays that I can dimension during runtime. Is there a way to
do that in VC++ .NET using arrays, or would I need to use vectors instead?

Daniel
 
Daniel said:
I need to use arrays that I can dimension during runtime. Is there a way to
do that in VC++ .NET using arrays, or would I need to use vectors instead?

Daniel:

If this is a question about standard C++, you should have asked it in
microsoft.public.vc.language.

And the answer would have been: use std::vector.
 
David said:
Daniel:

If this is a question about standard C++, you should have asked it in
microsoft.public.vc.language.

And the answer would have been: use std::vector.

Or perhaps CArray (well, the OP didn't specify the library he was
using). Or something from System::Collections.

Regards.
 
What does OP stand for?

Daniel

Fernando Gómez said:
Or perhaps CArray (well, the OP didn't specify the library he was using).
Or something from System::Collections.

Regards.
 
If I use std::vector, would my code still be portable to other .NET runtimes
on top of other platforms?

Daniel
 
Daniel said:
If I use std::vector, would my code still be portable to other .NET
runtimes on top of other platforms?

C++ code for .NET is only portable if
(1) You are using VC2005 or newer
(2) You pass /clr:pure, which disallows a lot of native stuff. Whether
std::vector still works I can't say, it may even depend on the type you are
using it with.
 
Daniel said:
Why use that instead of ArrayList?

Daniel
I'd guess that it is because List<T> is type safe, so you won't have to
cast from object to you your particular type, etc.
 
Fernando said:
I'd guess that it is because List<T> is type safe, so you won't have
to cast from object to you your particular type, etc.

And additionally far more efficient when used with value types, because it
doesn't require boxing and unboxing operations, inlines better, etc.
 
Back
Top