zoukankan      html  css  js  c++  java
  • 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 还是 空指针了....

  • 相关阅读:
    TO DO List
    springboot 热部署
    <dependencyManagement>的作用
    人体工程学座椅
    temp
    temp
    声明式编程和命令式编程的本质区别
    weak first question
    Spring依赖注入方式和依赖来源
    SpringBoot 整合 H2 数据库
  • 原文地址:https://www.cnblogs.com/porter/p/3578264.html
Copyright © 2011-2022 走看看