David said:
I am only just starting to look at managed code (don't have the VC8
compiler yet!), but that is what I thought too. The old form does not
look like legal standard C++, but the new one is like
std::vector<MyClass *> * pMyArray = new std::vector<MyClass *>(100);
This is legal standard C++, though not what I would use (never use new
unless you have to). I would do
std::vector<MyClass *> myArray(100);
I definitely agree with you in native C++ (I almost never write a "new"
anymore in native code). Anyway, in the managed world, newing an object is
the only way to create it and register it with the GC (btw, this is the same
thing in Java). Now, as MC++ and C++/CLI are designed to be closer to the
metal than C# or VB, the syntax is a bit clumsy.
Now I read that C++/CLI has optional "stack semantics". So can I do
array<MyClass ^> myArray(100);
? Or is this not allowed? If not, why not?
It is not, and I don't know why :-( It seems that stack semantic is not
available for arrays...
Anyway, this is not really necessary here : The main goal of stack semantic
is not to ease syntax, it is to provide RAII. RAII has a meaning only if
there is some ressource to free, but an array does not hold any such
ressource (except memory of course, which is taken care of by the GC).
Arnaud
MVP - VC