Multiple Inheritance && MFC
Deepak Saxena~ -- dsaxena@sedona.intel.com
Friday, February 02, 1996
I'm in the process of designing an MFC application at the moment and am
wondering whether or not I should use multiple inheritance. I know that
the older versions of MFC are hellish to use with MI, but I was
wondering what sort of support MFC 4.0 has. I will be upgrading to MSVC
4.0 in the next week or so and will actually start coding in a while.
Most importantly, does CRuntimeClass support MI. My class hiearchy
right now has places where I have a class derived from three classes
which are all derived from the same class which is itself derived from
CObject:
class CA : public CObject;
class CB: public CA;
class CC: public CA;
class CD: public CA;
class CE: public CB, public CC, public CD;
with the new MFC, can I do:
CA *pA = GetCAObject();
if(pA->IsTypeOf(RUNTIME_CLASS(CC)))
{
// Do stuff here;
}
David J. Straley -- djs@cnj.digex.net
Saturday, February 03, 1996
[Mini-digest: 3 responses]
>
>I'm in the process of designing an MFC application at the moment and am
>wondering whether or not I should use multiple inheritance. I know that
>the older versions of MFC are hellish to use with MI, but I was
>wondering what sort of support MFC 4.0 has.
I've used Multiple inheritance successfully with MFC. There is a
Technical article on doing this. Make sure that your parent classes contain
only ONE CWnd-derived class, max, for starters. Also, you have to put that
CWnd class (if it exists) as the first or last class of the list of classes
(I forgot which - see the article). You'll also have to override "new" and
"delete". Just do what the article says in this and don't be frightened!
Also, if two or more of your parents have the same member function name,
like "Create()", you'll have to explicitly call the correct one when you are
trying to use it, i.e. "CWnd::Create()", for example.
Regards,
Dave Straley
David J. Straley, Software Developer --- djs@cnj.digex.net
"Right-sized solutions for most any-sized Enterprise"
Windows * Windows NT * Unix/X Windows
-----From: "John Elsbree"
(Please, let's not let this thread degenerate into a religious battle over
whether MFC should support MI...)
MFC 4.0 really hasn't changed any, with respect to MI. What you've seen in
previous versions still holds true in this version.
Sorry if this isn't the answer you were hoping to hear.
//mfcTeam.m_johnels; // does not represent Microsoft
-----From: mikeblas@interserv.com
On Fri, 2 Feb 1996, Deepak Saxena~ wrote:
>I'm in the process of designing an MFC application at the moment and am
>wondering whether or not I should use multiple inheritance.
You probably shouldn't.
>I know that
>the older versions of MFC are hellish to use with MI, but I was
>wondering what sort of support MFC 4.0 has.
MFC 4.0 doesn't (and MFC 4.1 won't) like MI, either.
>Most importantly, does CRuntimeClass support MI.
No.
>My class hiearchy
>right now has places where I have a class derived from three classes
>which are all derived from the same class which is itself derived from
>CObject:
>
>class CA : public CObject;
>class CB: public CA;
>class CC: public CA;
>class CD: public CA;
>
>class CE: public CB, public CC, public CD;
If this is really the only place you're using MI, you can _probably_ write
your own version of CRuntimeClass and let it do something else instead. You
can't subclass CRuntimeClass because nothing in it is virtual.
There was an article in Doctor Dobbs' Journal within the last 3 or 4 months
which explained how to graft some MI support into MFC. There's also a bunch
of files on CompuServe in the MSMFC fourm which demonstrate MI in MFC class
hierarchies.
Microsoft doesn't support any of these approaches.
.B ekiM
--
TCHAR szDisc[] = _T("These words are my own; I do not speak for Microsoft.");
Poul A. Costinsky -- wizsofti@datasrv.co.il
Sunday, February 04, 1996
I think MS didn't make any changes in their relationships with MI.
But VC 4 now supports RTTI (run-time type information), so
instead of CRuntimeClass you can use dynamic_cast etc.
There is a Technical note about MI and MFC, but it was written
before RTTI implementation (I think).
Hope this helps.
Regards,
Poul A. Costinsky(PoulACost@msn.com).
("`-''-/").___..--''"`-._
(`6_ 6 ) `-. ( ).`-.__.`)
(_Y_.)' ._ ) `._ `. ``-..-'
_..`--'_..-_/ /--'_.' ,'
(il).-'' (li).' ((!.-
Chong Zhang -- cz@dana.ucc.nau.edu
Sunday, February 04, 1996
[Mini-digest: 2 responses]
I have been using Multiple Inheritance for years with MFC. But we don't
use multiple MFC classes as base. Because MFC was not designed to support
multiple inheritance. As long as you use only ONE MFC class in your base,
you are all right.
Well, CRuntimeClass and all those related MACROs do not support M.I. I do
have a set of MACROs developed in house to support M.I. But I use them
only in my own libraries not in MFC. (I don't want to have a custom made
MFC runtime DLL.)
-----From: "Scot Wingo"
One more comment on this subject->
There were 2 articles that discussed MI and MFC in the
January Dr. Dobbs.
1. pg 84 - Jean-Louis Leroy "Multiple Inheritance for MFC 4.0"
-Seems to answer your needs right on the button.
2. pg 58 - "Extending MFC"
-Talks about how we use MI to have CWnd/CView derivatives, while
centralizing the drawing logic in a base class.
HTH,
Scot
| Вернуться в корень Архива
|