Author | Message | Time |
---|---|---|
Dyndrilliac | I've been trying to figure out how the correct syntax for creating a variable length array should go, and having very bad results. Here's what I've got:[code]array<Byte>^ MyBuffer[(const UInt32)i_len+4] = {0};[/code]I also tried:[list][*][code]Array ^MyBuffer = System::Array::CreateInstance(System::Byte::typeid, i_len+4);[/code] [*][code]Array *MyBuffer = System::Array::CreateInstance(System::Byte::typeid, i_len+4);[/code] [*][code]const UInt32 Len = (i_len+4); array<Byte>^ MyBuffer[Len] = {0};[/code][/list] All to no avail. Also MSDN spits up bunches of results in their Search utility with old syntax making it pretty worthless -.- I'm using .NET Framework 2.0 btw. | August 31, 2006, 6:59 PM |
K | A good tip is when searching for .NET 2.0 things, search http://msdn2.microsoft.com instead of msdn.microsoft.com. Also try using "C++/CLI" on google instead of "Managed C++" or "C++.NET" Oh, and [code] array<Byte>^ myarray = gcnew array<Byte>(Len); [/code] Just like in C#, all objects must be allocated with new; to differentiate the managed new from the standard c++ new, it is called "gcnew" garbage collected new). Edit: the carrot symbol means an item is a pointer to a managed object, as opposed to a pointer to a regular object (*). So to create an array of managed strings, you would do this: [code] array<String^>^ myarray = gcnew array<String^>(Len); [/code] HTH | August 31, 2006, 8:17 PM |
Dyndrilliac | Oh! Thanks for the info, now things make a lot more sense. I'm really starting to enjoy C++.net. The interoperability is really nice, as is garbage collection. | August 31, 2006, 9:49 PM |