use array or vector

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
 
D

David Wilkinson

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.
 
F

Fernando Gómez

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.
 
D

Daniel

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.
 
D

Daniel

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

Daniel
 
B

Ben Voigt [C++ MVP]

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.
 
F

Fernando Gómez

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.
 
B

Ben Voigt [C++ MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

stl vector 1
BUG: Non-vector array mess-up 3
unmanaged memory and large object heap 10
MC++ and /MD 2
vba array logic 3
Passing containers between C# and C++ 5
Newbie 5
Vector or List 2

Top