inighthawki Posted August 20, 2006 Posted August 20, 2006 in vb.net, if i wanted to convert types, i could use directcast and return a value from say an object: Dim AL As ArrayList AL = DirectCast(BinaryFormatter.Deserialize(FileStream), ArrayList) and it could convert it to an arraylist, im trying to do the same in C++, but apparently C++ doesnt have the directcast function, and its not under the convert functions (::System::Convert::???) any help appreciated, thx in advance Quote
Administrators PlausiblyDamp Posted August 20, 2006 Administrators Posted August 20, 2006 Have you tried the C# style cast syntax? AL = (ArrayList) BinaryFormatter.Deserialize(FileStream); That should work as C#'s syntax is taken from the C / C++ way of doing things. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
inighthawki Posted August 20, 2006 Author Posted August 20, 2006 i'll try later when i get the chance, thx for thr response, u guys alwasy seem to answer so quickly here reguardless the fact that nobody posts :P Quote
Leaders snarfblam Posted August 20, 2006 Leaders Posted August 20, 2006 I think a dynamic cast would be the closest to a DirectCast. C-style casts are considered bad practice by many--it is very flexible, but as a result sometimes what exactly it will do is hard to predict. A dynamic cast is the only non-C-style cast that will perform type checking (like any .Net cast). someType someVarialbe = dynamic_cast<someType> (anotherVariable); Quote [sIGPIC]e[/sIGPIC]
inighthawki Posted August 20, 2006 Author Posted August 20, 2006 thx for the response, though plausiblydamp's idea did work, and as far as im concerned is fine for right now lol... Quote
David Anton Posted August 21, 2006 Posted August 21, 2006 (edited) safe_cast is yet another alternative: ArrayList ^AL = nullptr; AL = safe_cast<ArrayList^>(BinaryFormatter::Deserialize(FileStream)); Edited August 21, 2006 by David Anton Quote
Leaders snarfblam Posted August 21, 2006 Leaders Posted August 21, 2006 From what I've read after posting, dynamic_cast is closest to VB's TryCast (C# "as" keyword) and safe_cast is closest to VB's DirectCast. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.