Template assignment operator overloading mystery

前端 未结 2 1410
醉话见心
醉话见心 2020-12-06 03:23

I have a simple struct Wrapper, distinguished by two templated assignment operator overloads:

template
struct Wrapper {

  Wra         


        
2条回答
  •  春和景丽
    2020-12-06 03:30

    From the C++03 standard, §12.8/9:

    A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&, const X&, volatile X& or const volatile X&.

    And §12.8/10:

    If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly.

    The fact that your operator= is a template makes it not a copy assignment operator, so the class' implicit copy assignment operator is still generated by the compiler.

提交回复
热议问题