Implicit conversion when overloading operators for template classes

前端 未结 3 1805
终归单人心
终归单人心 2020-12-02 20:59

I would like to know why implicit type conversion doesn\'t work with outside operator overloading on class templates. Here is the working, non-templated version:

<         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 21:32

    All possible foo are equally valid conversions from int since the constructor takes int, not the template type. The compiler isn't able to use the other parameter in the operator to guess which one you might mean, so you get the error. If you explicitly tell it which instantiation you want I believe it would work.

提交回复
热议问题