Topic: When must an implictly defined assigment operator be generated


Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/11/12
Raw View
Jody Goldberg <jody+@cmu.edu> wrote:
>class A
>{
>    A & operator=(A const &);  // it is private
                 ^
                 correction
>};
>
>class B : public A
>{
>};
>// B does not define a copy assignment operator and it is not called in the
>// translation unit
>// WP 12.8 para 12 states that implicitly defining a copy assigment operator
>// makes the program ill formed only if it is called.  Can a conformant
>// compiler compile the above code without error ?

The question is "MUST ..." and the answer is if you add:

main() {}

to the above and say it is a complete program then
a conforming translator is required to compile and
execute the code correctly.

If you wrote

main() { B b1, b2; b1=b2; }

then a diagnostic would be required --
"Can't generate B copy assignment because A
assignment is inaccessible" for example.



--
John Max Skaller               voice: 61-2-566-2189
81 Glebe Point Rd              fax:   61-2-660-0850
GLEBE NSW 2037                 email: maxtal@suphys.physics.oz.au
AUSTRALIA                      email: skaller@maxtal.com.au
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]