home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!ms!ms.cs.wm.edu!greg
- From: greg@ms.cs.wm.edu (Gregory S. Miller)
- Subject: Questions about Constructors and pointers to objects in TP 6
- Message-ID: <1993Jan22.171839.4925@cs.wm.edu>
- Sender: news@cs.wm.edu (News System)
- Nntp-Posting-Host: ms.cs.wm.edu
- Organization: College of William & Mary, founded 1693
- Date: Fri, 22 Jan 1993 17:18:39 GMT
- Lines: 44
-
- Is it legal for the constructor for an object to call the constructor for a
- parent object?
-
- I am having some difficulty with virtual method calls going to the wrong
- class method, and was wondering if I might be accidentally overwriting
- the pointer to the VMT by calling the parent class constructor from within
- the descendant class constructor.
-
- A pointer of type pClass is assignment-compatible with ALL descendants of
- Class, correct?
-
- As a result, the following should work:
-
- New(pDescendantPtr,Init(Stuff));
- .
- .
- .
- pClassPtr := pDescendantPtr;
- .
- .
- .
- pClassPtr^.VirtualMethod; { executes Descendant.VirtualMethod, right? }
-
-
- Would this still work?
-
- var
- Ptr : Pointer;
- Classptr: pClass;
- Descend : pDescendant;
-
- Classptr := Descend;
- Ptr := Classptr;
- pClass(Ptr)^.Virtualmethod; { still execute Descendant.VirtualMethod? }
-
- In my code, which I will not post yet, calls like that above sometimes go to the
- correct place, but sometimes they go to the parent.VirtualMethod, and sometimes
- they go to Sibling.VirtualMethod -- the method implementation for an entirely
- seperate descendant of Class! Any ideas? Places in my code that might be the
- cause of the trouble?
-
- Any feedback would be appreciated.
-
- Greg
-