title: Function Overloading and Variable Number of Parameters
body: <p>I've made and exercise on variable number of parameters:</p>
  <pre><code>import std.stdio;
  
  void main() {
      
      enum Operation { add, subtract, multiply, divide }
      
      struct Calculation {
          Operation op;
          double first;
          double second;
      }
      
      double calculate1(in Calculation c) {
          double result;
          switch (c.op) {
              case Operation.add : {
                  result = c.first+c.second;
                  break;
              }
              default : {
                  break;
              }
          }
          return result;
      }
      
      double[] calculate(in Calculation[] ccs...){
          double[] result;
          foreach(c;ccs){ 
              result ~= calculate1(c);
          }
          return result;
      }
      
      writeln(calculate1(Calculation(Operation.add, 1.1, 2.2)));
      
      writeln(calculate
              ([Calculation(Operation.add, 2.1, 2.2)
               ,Calculation(Operation.add, 2.1, 2.2)
               ,Calculation(Operation.add, 2.1, 2.2)
               ,Calculation(Operation.add, 2.1, 2.2)]
               )
             );
  }
  </code></pre>
  <p>It works ok:</p>
  <blockquote>
  <p>3.3</p>
  <p>[4.3, 4.3, 4.3, 4.3]</p>
  </blockquote>
  <p>Then I've tried to try overload function <code>calculate</code> and change <code>calculate1</code> name to <code>calculate</code>. And it brings this errors:</p>
  <blockquote>
  <p>(27): Error: declaration calculate is already defined</p>
  <p>(38): Error: function calculate (const(Calculation) c) is not callable using argument types (Calculation[])</p>
  </blockquote>
  <p>I can't get it. Is this kind of declaration brings ambiguity and compiler tries to send Calculation[] as Calculation argument? And is it possible to overload <code>calculate</code> function in this program?</p>
  <p>EDIT: When removing <code>...</code> from line <code>double[] calculate(in Calculation[] ccs...){</code> ambiguity vanishes. Now having types <code>Calculation[]</code> and <code>Calculation</code> as arguments, error message is still the same.</p>
  <p>EDIT2. Interesting find by  rcorre. Moving overloaded function <code>calculate</code> from <code>main</code> to upper scope this overload totally works.</p>