<tfoot id='yQ5rw'></tfoot>

    • <bdo id='yQ5rw'></bdo><ul id='yQ5rw'></ul>

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

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

      <legend id='yQ5rw'><style id='yQ5rw'><dir id='yQ5rw'><q id='yQ5rw'></q></dir></style></legend>

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

        Strange ambiguous call to overloaded function error(对重载函数错误的奇怪模棱两可的调用)

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

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

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

                  问题描述

                  我正在努力

                  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).

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                  Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                  What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                  What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)
                  <i id='GopgA'><tr id='GopgA'><dt id='GopgA'><q id='GopgA'><span id='GopgA'><b id='GopgA'><form id='GopgA'><ins id='GopgA'></ins><ul id='GopgA'></ul><sub id='GopgA'></sub></form><legend id='GopgA'></legend><bdo id='GopgA'><pre id='GopgA'><center id='GopgA'></center></pre></bdo></b><th id='GopgA'></th></span></q></dt></tr></i><div id='GopgA'><tfoot id='GopgA'></tfoot><dl id='GopgA'><fieldset id='GopgA'></fieldset></dl></div>

                  • <bdo id='GopgA'></bdo><ul id='GopgA'></ul>
                      <tbody id='GopgA'></tbody>

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

                        <tfoot id='GopgA'></tfoot>
                        <legend id='GopgA'><style id='GopgA'><dir id='GopgA'><q id='GopgA'></q></dir></style></legend>