Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!jarthur!uunet!bywater!arnor!watson!blinn.watson.ibm.com!mittle From: mittle@blinn.watson.ibm.com (Josh Mittleman) Newsgroups: comp.lang.c++ Subject: Re: Can I make overloaded operator functions virtual? Message-ID: <1991Mar21.184133.14506@watson.ibm.com> Date: 21 Mar 91 18:41:33 GMT References: <1991Mar20.074256.334@csis.dit.csiro.au> Sender: @watson.ibm.com Reply-To: mittle@ibm.com Distribution: usa Organization: IBM T. J. Watson Research Lines: 45 The problem you describe is precisely the same one addressed earliest this week under the subject "Seeking neat way to do binary "virtual" functions. A followup post by cok@islsun.kodak.com suggests some ways around the problem, but also ntoes that a more fundmanetal solution is really needed. I've run across the same problem in another context, and I have what might be a reasonable solution. I would appreciate comments. What we need is a new kind of template or prototype for a class, so that the compiler can be told to treat certain class names as parameters. To work with the most recent example: class Base { public: virtual int operator==(const Base&); }; class Derived : public Base { public: int operator==(const Derived&); }; We would really like Derived::operator== to match the virtual Base::operator==, but we need to be able to treat the argument as a Derived&. My solution is somehow to tell the compiler that Base& is to be treated as a parameter of the parameterized class Base in certain circumstances. A possible syntax: class Base(parameter Base) // Defines formal parameters { public: virtual int operator==(parameter const Base&); // parameterized virtual // function. }; This seems to solve the problems suggested, and makes a great deal of sense to me. It requires the designer of class Base to forsee which members will need to be parameterized; I'm not sure if that is a good thing or not. Comments? =========================================================================== Josh Mittleman (mittle@ibm.com or joshua@paul.rutgers.edu) J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY 10598