beshers@fork.columbia.edu (Clifford Beshers) (10/13/88)
// The following code illustrates a bug in cfront 1.2.1 // The operator= member does not get inherited properly. // It can be invoked with the syntax b.operator=(a), but not // with b=a. #include <stream.h> class base_class { int d; public: base_class(int s) { d = s; } ~base_class() {} base_class& operator=(base_class& b) { d = b.d; return *this; } int data() { return d; } }; class derived_class : public base_class { public: derived_class(int i) : (i) { } }; main(int argc, char * argv[]) { derived_class a(1); derived_class b(2); b.operator=( a ); // This compiles. b = a; // This does not. } Cliff Beshers Columbia University Computer Science Department beshers@sylvester.columbia.edu
patrick@cs.cornell.edu (Pat Stephenson) (10/13/88)
In article <5936@columbia.edu>, beshers@fork (Clifford Beshers) writes: >// The following code illustrates a bug in cfront 1.2.1 >// The operator= member does not get inherited properly. >// It can be invoked with the syntax b.operator=(a), but not >// with b=a. > This is not a bug - at least not the way you think. The C++ reference manual states: (8.5.3, page 277): "Assignment is not implicitly defined (see 7.14 and 8.5) for objects of a class derived from a class for which "operator=" has been defined (8.5.11)." 7.14 says: "Object of some derived classes cannot be assigned; see 8.5.3" On page 171, the book says: " ... a use of the operator is only shorthand for an explicit call of the operator function" I conclude that the real bug is that cfront allows "b.operator=(a)". Pat ------------------------------------------------------------------------------- Pat Stephenson Computer Science Department pat@cs.cornell.edu Cornell University 607-255-8597 Ithaca NY 14850 -------------------------------------------------------------------------------- Pat Stephenson Computer Science Department pat@cs.cornell.edu Cornell University 607-255-8597 Ithaca NY 14850