Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!microsoft!jimad From: jimad@microsoft.UUCP (JAMES ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: virtual assignment operator is possible? Keywords: assignment operator, virtual function Message-ID: <10137@microsoft.UUCP> Date: 3 Jan 90 20:50:51 GMT References: <1989Dec30.174745.8174@sdr.slb.com> Reply-To: jimad@microsoft.UUCP (JAMES ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 17 Try defining the following: virtual B& B::operator=(const B&) virtual B& D::operator=(const B&) [virtual?]D& D::operator=(const D&) Then when using generic pointers to your base class B the second op= will be used to assign to a D pointed to. When using pointers of type D the third op= will be used. In the second op=, if you cannot create a D from a B in general, but only when the B& is really to a D -- then you'll have to resort to runtime checking, and complain at runtime if someone passes you a non-D. Make the third op= virtual if you want to allow the same choices in subclasses of D. If D won't be subclassed, it would be faster to not make the 3rd op= virtual. You'll probably want to define a D::D(B&) too. Alternately, make all your op='s return void, and don't support the infrequent cases where assignment is used for value.