title: cpp operator overloading inside std::function
body: <p>I create a <code>complex</code> struct in <code>complex.h</code> and overload a series of operators (including <code>^</code>) to work on the four operations <code>complex+double</code>, <code>double+double</code>, <code>complex+complex</code>, <code>double+complex</code>:</p>
  <pre><code>complex operator^(complex&amp; lhs, complex&amp; rhs){
      double new_mag = std::pow(mag(lhs), rhs.re);
      double new_arg = angle(lhs.re, lhs.im) * rhs.re;
      return complex(new_mag * std::cos(new_arg), new_mag * std::sin(new_arg)); 
  }
  </code></pre>
  <p>I then define two structs in the file <code>calc.cpp</code> which includes <code>complex.h</code>, namely <code>op</code> and <code>func</code>:</p>
  <pre><code>struct op{
      char symbol;
      uint8_t precedence;
      uint8_t assoc;
      uint8_t type;
  
      std::function&lt;complex (complex, complex)&gt; operate;
  
  };
  
  struct func{
      std::string symbol;
      uint8_t type;
  
      std::function&lt;complex (complex, complex)&gt; operate;
  
  };
  </code></pre>
  <p>Where each struct also defines a functional. I then attempt to initialize objects of these structs in the same file:</p>
  <pre><code>op op6{'^', 4, RIGHT, BINARY, [] (complex a, complex b){return b ^ a;}}; // no errors
  
  // no operator &quot;^&quot; matches these operands -- operand types are: complex ^ complex
  func f10{&quot;sqrt&quot;, ONE_INPUT, [] (complex a, complex b){return a ^ complex(1/2);}};
  </code></pre>
  <p>I also tried leaving <code>complex(1/2)</code> just as the double <code>.5</code> but that gave me the same error, except with operand types <code>complex ^ double</code>.</p>
  <p>My question is how can operator <code>^</code> not match operands of type <code>complex</code> when it is defined to do so, and DOES do so in the initialization of <code>op6</code>?</p>