home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8443 < prev    next >
Encoding:
Text File  |  1993-01-22  |  1.6 KB  |  56 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!ms!ms.cs.wm.edu!greg
  3. From: greg@ms.cs.wm.edu (Gregory S. Miller)
  4. Subject: Questions about Constructors and pointers to objects in TP 6
  5. Message-ID: <1993Jan22.171839.4925@cs.wm.edu>
  6. Sender: news@cs.wm.edu (News System)
  7. Nntp-Posting-Host: ms.cs.wm.edu
  8. Organization: College of William & Mary, founded 1693
  9. Date: Fri, 22 Jan 1993 17:18:39 GMT
  10. Lines: 44
  11.  
  12. Is it legal for the constructor for an object to call the constructor for a
  13. parent object?
  14.  
  15. I am having some difficulty with virtual method calls going to the wrong
  16. class method, and was wondering if I might be accidentally overwriting
  17. the pointer to the VMT by calling the parent class constructor from within 
  18. the descendant class constructor.
  19.  
  20. A pointer of type pClass is assignment-compatible with ALL descendants of
  21. Class, correct?
  22.  
  23. As a result, the following should work:
  24.  
  25.     New(pDescendantPtr,Init(Stuff));
  26.     .
  27.     .
  28.     .
  29.     pClassPtr := pDescendantPtr;
  30.     .
  31.     .
  32.     .
  33.     pClassPtr^.VirtualMethod;  { executes Descendant.VirtualMethod, right? }
  34.  
  35.  
  36. Would this still work?
  37.  
  38.     var
  39.         Ptr    : Pointer;
  40.         Classptr: pClass;
  41.         Descend    : pDescendant;
  42.  
  43.     Classptr := Descend;
  44.     Ptr := Classptr;
  45.     pClass(Ptr)^.Virtualmethod;  { still execute Descendant.VirtualMethod? }
  46.  
  47. In my code, which I will not post yet, calls like that above sometimes go to the
  48. correct place, but sometimes they go to the parent.VirtualMethod, and sometimes
  49. they go to Sibling.VirtualMethod -- the method implementation for an entirely
  50. seperate descendant of Class!  Any ideas?  Places in my code that might be the
  51. cause of the trouble?
  52.  
  53. Any feedback would be appreciated.
  54.  
  55. Greg
  56.