Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!munnari.oz.au!manuel!csis!stuarth From: stuarth@csis.dit.csiro.au (Stuart Hungerford) Newsgroups: comp.lang.c++ Subject: Can I make overloaded operator functions virtual? Message-ID: <1991Mar20.074256.334@csis.dit.csiro.au> Date: 20 Mar 91 07:42:56 GMT Distribution: usa Organization: csis.dit.csiro.au Lines: 38 I'd like to be able to make overloaded operator functions virtual. Say I had this: class Base { public: virtual int operator== (const Base& B); //... }; then I'd like to override this virtual function in a derived class of Base. BUT the language requires that overriding virtual functions requires an exact match so I have to say: class Derived : public Base { public: int operator== (const Base& B); //... }; which means I'll probably end up casting Base classes to Derived ones in the implementation of Derived::operator==. I guess the same problem will hold with any function that takes class references or pointers as arguments. Am I missing something important here? How do you handle this kind of situation? Any advice much appreciated. Stuart +---------------------------------------------------------------------------+ | Internet : stuarth@csis.dit.csiro.au | | | Voice : +61-6-2750941 | _--_|\ | | Fax : +61-6-2571052 | / \ | | Postal : CSIRO Division of Information Technology, | \_.--._/ | | GPO Box 664, Canberra ACT 2601 | v | | AUSTRALIA | | +---------------------------------------------------------------------------+