Why the default assignment operator is not synthesized by the compiler if the class has a reference data element

In C ++, if a class has a reference data element, the default assignment operator is not synthesized by the compiler. What for?

+5
source share
2 answers

In C ++, if a class has a reference data element, the default assignment operator is not synthesized by the compiler. Why?

What copy assignment should do is defined in:

C ++ 03 Standard 12.8 / 13:

Each subobject is assigned according to its type:

  • if the subobject has a class type, the instance assignment operator for the class is used (as if it were explicitly qualified, i.e. ignored any possible functions of virtual redefinition in more derived classes);

  • , ;

  • , .

,
,
?
:

  • , , [Ref 1].
  • #1 , , .

, . , ++ , , , , .

:
++ 03 12.8/12:

, , . , , , :
 .......
 - ,
 .......


[Ref 1]
++ 03 8.5.3/2:

. , , . (5.2.2) (6.6.3) .

+6

. , .

++ N3337 ยง12.8.23:

/ X , X :

  • , X - ,
  • const non-class ( )
  • M ( ), /, (13.3) Ms , , ,
  • B, /, (13.3), Bs, ,
  • , , .
+4

All Articles