Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!ub!boulder!uswat!randyh From: randyh@uswat.uswest.com ( Randy Hughes #3000 x2116 ) Newsgroups: comp.lang.c++ Subject: Operator Inheritance Message-ID: <11087@uswat.UUCP> Date: 14 Sep 90 16:58:47 GMT Sender: news@uswat.UUCP Organization: US WEST Advanced Technologies, CO, USA Lines: 66 I am currently writing a library that will be used by applications through inheritance. I would like the base classes in the library to provide operators that are accessible by the derived class objects in the application. Consider the following simple example: class base // in the library { public: int x; base &operator=(int v) { x = v; return *this; } base &operator+=(int v) { x += v; return *this; } base operator+(int v) { base x = *this; x += v; return *this; } }; class derived: public base // in the application { }; main() { derived d; d = 1; // bombs on compilation (cannot make a derived) d += 1; // compiles d = d; // compiles d = (d += 1); // bombs on compilation (cannot make a derived) d + 1; // compiles (gives warning about result not used) d = d + 1; // bombs on compilation (cannot make a derived) } My questions are: 1) Are the failures due to base objects not being able to be assigned to derived objects? 2) Changing the derived class to: class derived: public base // in the application { public: derived() { } derived(const base &b):base(b) { } }; to allow the conversion from base to derived gives compilation errors seeming to indicate that the operator= function from the base class is indeed not inherited. Is operator= handled specially in inheritance? 3) Is there any way to allow the derived class to use all the base class operators without requiring additions to the derived class (my guess is no)? 4) What is the least amount of work required for the derived class to be able to use all of the base class operators? I don't want to put much burden on the user of the library base class. Also, the number of base class operators may be extensive. ------------------------------------------- Randy Hughes U S WEST Advanced Technologies