<bdo id='9QKd2'></bdo><ul id='9QKd2'></ul>
  • <tfoot id='9QKd2'></tfoot>

      1. <legend id='9QKd2'><style id='9QKd2'><dir id='9QKd2'><q id='9QKd2'></q></dir></style></legend>
        <i id='9QKd2'><tr id='9QKd2'><dt id='9QKd2'><q id='9QKd2'><span id='9QKd2'><b id='9QKd2'><form id='9QKd2'><ins id='9QKd2'></ins><ul id='9QKd2'></ul><sub id='9QKd2'></sub></form><legend id='9QKd2'></legend><bdo id='9QKd2'><pre id='9QKd2'><center id='9QKd2'></center></pre></bdo></b><th id='9QKd2'></th></span></q></dt></tr></i><div id='9QKd2'><tfoot id='9QKd2'></tfoot><dl id='9QKd2'><fieldset id='9QKd2'></fieldset></dl></div>

      2. <small id='9QKd2'></small><noframes id='9QKd2'>

        对重载函数错误的奇怪模棱两可的调用

        时间:2023-10-06

            • <bdo id='7nhva'></bdo><ul id='7nhva'></ul>

                1. <small id='7nhva'></small><noframes id='7nhva'>

                  <i id='7nhva'><tr id='7nhva'><dt id='7nhva'><q id='7nhva'><span id='7nhva'><b id='7nhva'><form id='7nhva'><ins id='7nhva'></ins><ul id='7nhva'></ul><sub id='7nhva'></sub></form><legend id='7nhva'></legend><bdo id='7nhva'><pre id='7nhva'><center id='7nhva'></center></pre></bdo></b><th id='7nhva'></th></span></q></dt></tr></i><div id='7nhva'><tfoot id='7nhva'></tfoot><dl id='7nhva'><fieldset id='7nhva'></fieldset></dl></div>

                    <tbody id='7nhva'></tbody>
                  <legend id='7nhva'><style id='7nhva'><dir id='7nhva'><q id='7nhva'></q></dir></style></legend>
                2. <tfoot id='7nhva'></tfoot>
                  本文介绍了对重载函数错误的奇怪模棱两可的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在努力

                  void function(int y,int w)
                  {
                      printf("int function");
                  
                  }
                  
                  
                  void function(float y,float w)
                  {
                      printf("float function");
                  }
                  
                  
                  int main()
                  {
                      function(1.2,2.2);
                      return 0;
                  }
                  

                  我收到一个错误错误,例如..

                  I get an error error like..

                  error C2668: 'function' : ambiguous call to overloaded function
                  

                  当我尝试调用 function(1.2,2)function(1,2.2) 时,它打印为int function"

                  and when I try to call function(1.2,2) or function(1,2.2) it is printing as "int function"

                  请说明function(float y,float w)什么时候被调用?

                  Please clarify when will the function(float y,float w) be called?

                  推荐答案

                  看gcc报错信息:

                  a.cpp:16: error: call of overloaded ‘function(double, double)’ is ambiguous
                  a.cpp:3: note: candidates are: void function(int, int)
                  a.cpp:9: note:                 void function(float, float)
                  

                  对任一函数的调用都需要截断,这就是为什么两者都不优于另一个的原因.我怀疑你真的想要 void function(double y,double w).请记住,在 C/C++ 中,文字和参数传递的默认浮点类型是 double,而不是 float.

                  A call to either function would require truncation, which is why neither is preferred over the other. I suspect you really want void function(double y,double w). Remember that in C/C++, the default floating-point type for literals and parameter passing is double, NOT float.

                  更新

                  如果您真的不想将函数签名float更改为double,您可以随时使用literals 类型为 float.如果您将后缀 f 添加到 浮点数,它们将被输入浮点数.

                  If you really don't want to change the function signature from float to double, you can always use literals that are typed as float. If you add the suffix f to the floating point numbers, they will be typed float.

                  您的示例将是 function(1.2f, 2f)function(1, 2.2f).

                  Your examples would then be function(1.2f, 2f) and function(1, 2.2f).

                  这篇关于对重载函数错误的奇怪模棱两可的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:奇怪的 MSC 8.0 错误:“ESP 的值没有在函数调用中正 下一篇:是否可以强制不内联函数?

                  相关文章

                  最新文章

                  <i id='oEc0m'><tr id='oEc0m'><dt id='oEc0m'><q id='oEc0m'><span id='oEc0m'><b id='oEc0m'><form id='oEc0m'><ins id='oEc0m'></ins><ul id='oEc0m'></ul><sub id='oEc0m'></sub></form><legend id='oEc0m'></legend><bdo id='oEc0m'><pre id='oEc0m'><center id='oEc0m'></center></pre></bdo></b><th id='oEc0m'></th></span></q></dt></tr></i><div id='oEc0m'><tfoot id='oEc0m'></tfoot><dl id='oEc0m'><fieldset id='oEc0m'></fieldset></dl></div>

                      <bdo id='oEc0m'></bdo><ul id='oEc0m'></ul>

                      <tfoot id='oEc0m'></tfoot>
                    1. <legend id='oEc0m'><style id='oEc0m'><dir id='oEc0m'><q id='oEc0m'></q></dir></style></legend>

                      <small id='oEc0m'></small><noframes id='oEc0m'>