In native C++, the closest equivalent to the standard VB casting macros (CType and the corresponding CInt, CStr, etc.) is static_cast. The main exception are casts from floating point types to integer types (e.g., CInt(myDouble)) - in these cases, you need a method to perform VB 'banker's rounding' (our VB to C++ Converter inserts a helper class for this).
In C++/CLI, the closest equivalent are calls to the System::Convert methods if the appropriate method exists, otherwise they are converted to the safe_cast operator.
The behavior of all of these methods may be subtly different from the VB casting macros though, so you should always test the behavior of your converted C++ code.
The VB TryCast operator is converted to the C++ dynamic_cast operator.
|x = CType(myObject, FooType)
x = TryCast(myObject, FooType)
|x = static_cast<FooType*>(myObject);
x = dynamic_cast<FooType*>(myObject);
Use VB to C++ Converter to convert from VB to C++.
Copyright © 1997 – 2017 Tangible Software Solutions Inc.