如何最好转换VARIANT_BOOL到C ++的布尔? [英] How to best convert VARIANT_BOOL to C++ bool?
问题描述
在使用COM布尔值作为在wtypes.h声明的短的VARIANT_BOOL传递。也有predefined值的真正的和的假的:
When using COM boolean values are to be passed as VARIANT_BOOL which is declared in wtypes.h as short. There are also predefined values for true and false:
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)
这是从VARIANT_BOOL转换成C ++的最好办法布尔
键入?显而易见的变体是:
Which is the best way to convert from VARIANT_BOOL to C++ bool
type? Obvious variants are:
-
与VARIANT_FALSE比较
compare with VARIANT_FALSE
只是投为bool
其他方法可以很容易地创造。
Other ways can be easily invented.
这是做到这一点的最好方法? - 最可读的,最非标准兼容的,最不容易accidential错误种植和最不容易的问题与移植到64位平台。
Which is the best way to do this - most readable, most standart-compliant, least prone to accidential bugs planting and least prone to issues with porting to 64-bit platforms?
推荐答案
相较于 VARIANT_FALSE
。有很多车code的在那里,错误地通过在C ++布尔真正
值(转换为整数值1)函数期待 VARIANT_BOOL
。如果你比较 VARIANT_FALSE
,你仍然会得到正确的期望值。
Compare to VARIANT_FALSE
. There is a lot of buggy code out there that mistakenly passes in the C++ bool true
value (cast to the integer value 1) to a function expecting VARIANT_BOOL
. If you compare to VARIANT_FALSE
, you will still get the correct expected value.
这篇关于如何最好转换VARIANT_BOOL到C ++的布尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!