Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

C++ Equivalent to VB Casts

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.

If you need to convert from VB to C++ and you are depending on the results being reliable and accurate, then you will want to have VB to C++ Converter, the best VB to C++ converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.