David, I think most of the committee understands this well, having experience in OOP. I am a newcomer to OOP, so I was not sure of this. I think the sentences I originally quoted from 8.19 are very unclear, as you agreed, and should be reworded. As for my last two questions, I understood correctly and came to the correct conclusions, but I think the LRM should be explicit about them. I had to make deductions based on what the LRM does not say, not based on what it does say. I will file a Mantis on these items. I have to teach this material, so it was important to me to understand it myself. Enjoy your vacation. Thanks very much, Shalom > -----Original Message----- > From: David Jones [mailto:djones@xtreme-eda.com] > Sent: Friday, January 02, 2009 3:16 PM > To: Bresticker, Shalom > Cc: sv-ec@server.eda.org > Subject: Re: [sv-ec] virtual methods > > > Leaf l = new; > > Derived d = l; > > > > 1. From d, can I access a method M or property P that is > defined in Leaf, but not in Derived? > > No. > > > I understand that if M or P is defined in both Derived and > then overriden in Leaf, then d.P (or M) gives me Derived::P > (or M), not Leaf::P (or M), but is d.P (or M) legal if there > is no Derived::P (or M)? > > Methods and properties are different, as there is no such > thing as a virtual property, so lumping P amd M in the same > statement will be confusing. The "virtual" feature works with > methods only. > > If you define D::P and then Leaf::P, these are two separate > properties. Leaf::P can never be accessed from d. > > In your example, d.M() will call Derived::M if M is not > virtual in Derived, or Leaf::M if it is. > > Any access from d must reference a definition available to > Derived, without recourse to Leaf. If you have a member > Derived::P then a reference from d will always pick up > Derived::P. It can't see Leaf at all. You must have a member > Derived::M for a call d.M() to be legal; Leaf::M will be > called only if Derived::M exists and is virtual. > > > > > 2. Declaring a method as virtual in Derived (e.g., pow()) > means that d.pow() will give me Leaf::pow() instead of > Derived::pow(). Is there any equivalent of a virtual method > for properties? That is, if property P is defined in both > Derived and Leaf, is there any way for d.P to give me > Derived::P instead of Leaf::P? There does not seem to be. > > There is no equivalent. You can "fake it" by defining a > virtual method getSomeProperty() in Derived, and then > implementing it appropriately in both Derived and all its > subclasses. This is common in OOP. > > Would it help you or the committee to understand this better > if I prepared a document explaining how this stuff works > under the hood? > Sometimes understanding the implementation helps to > understand the concept. If you want such a document then you > MUST reply IMMEDIATELY: > I am 9 hours behind Israel timewise, and I'm about to leave > on a 2-week vacation to Hawaii, so if you want this I will > have to get to it today. > --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Fri Jan 2 06:06:05 2009
This archive was generated by hypermail 2.1.8 : Fri Jan 02 2009 - 06:06:34 PST