c/c++ 重载 数组 操作符[] operator[ is ambiguous, as 0 also mean a null pointer of const char* type....


// Note: //int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type. int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work. int z = a[0u].GetInt(); // This works too.

0u  = SizeType(0)
 

Json::Value作为数组时,读取0位置时,出现错误:Use of overloaded operator [] is ambiguous

Use of overloaded operator [] is ambiguous (with operand types 'const Json:Value' and 'int' )

 

    void Parse(constJson::Value &jsonObject) {

      rmb = jsonObject[0].asDouble();

    }

 

Json:Value[]运算符支持输入的非负整型,即UInt或unsigned int。

而0作为索引值,也可能为空指针输入, 类型检查无法通过。

 

修改如下即可:

rmb = jsonObject[0U].asDouble();

或者:

rmb = jsonObject[SizeType(0)].asDouble();

 

说明:  0U   表示 无符号的整数,   这样写在自己的数组操作符重载的时候 区分 0 是 数值0 还是 空指针了....

 

转载于:https://www.cnblogs.com/porter/p/3578264.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值