home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Multiple Inheritance Problem
- Message-ID: <9224511.24381@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Aug31.230311.4668@speedy.aero.org>
- Date: Tue, 1 Sep 1992 01:37:06 GMT
- Lines: 28
-
- don@surtsey.aero.org (Don C. Hancock) writes:
-
- >I'm confused as to why the following results in what to me is the wrong
- >virtual function being called. I'm sure the problem is somehow caused
- >by my casting the result of the function call from one base to the
- >other (and somehow lying to the compiler), but I'm not sure how else to
- >accomplish my task.
-
- Yes, that is exactly what is causing the problem.
- You can fix it by inserting an extra cast to (derived *) before
- casting to (base2 *), ie.
-
- main() {
- base2 *bb2 = (base2 *)(derived *)fun();
- bb2->v2(); // prints der::v2 as desired
- }
-
- BUT, I would strongly recommend *against* using these sort of casts.
-
- Maybe you could explain in a bit more detail why you think that you
- need to downcast from a (base *) to a (base2 *), and then we may
- be able to give you an alternative solution :-)
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-