<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: MFC and Multiple Inheritance</title>
	<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/</link>
	<description>Windows, Web and Stuff</description>
	<pubDate>Thu, 28 Aug 2008 13:47:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Bill Zitomer</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-26</link>
		<dc:creator>Bill Zitomer</dc:creator>
		<pubDate>Fri, 12 Oct 2007 16:46:38 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-26</guid>
		<description>I know, not my choice to use MFC either. Yeah I saw your name on Steve's blogroll. Thanks for the conversation! :)</description>
		<content:encoded><![CDATA[<p>I know, not my choice to use MFC either. Yeah I saw your name on Steve&#8217;s blogroll. Thanks for the conversation! <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Ballman</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-23</link>
		<dc:creator>Aaron Ballman</dc:creator>
		<pubDate>Fri, 12 Oct 2007 16:03:42 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-23</guid>
		<description>Weird...well, I've always avoided MFC whenever possible, so this is entirely likely to be out of my scope.  I hate MFC and don't envy you!  ;-)

In any event, nice blog!  Steve pointed it out to me, in case you're wondering where I came from.  :-)</description>
		<content:encoded><![CDATA[<p>Weird&#8230;well, I&#8217;ve always avoided MFC whenever possible, so this is entirely likely to be out of my scope.  I hate MFC and don&#8217;t envy you!  <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In any event, nice blog!  Steve pointed it out to me, in case you&#8217;re wondering where I came from.  <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Zitomer</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-22</link>
		<dc:creator>Bill Zitomer</dc:creator>
		<pubDate>Fri, 12 Oct 2007 15:46:30 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-22</guid>
		<description>Well, yeah, the virtual base class is what would make this work, but the problem is you get compile errors because of how MFC is implemented (something to do with the message mapping). That was one of the articles I linked (the one that says MI is not required for serious applications).

The reason I want to do it this way, is because 95% of the code for my control class is the same. It's mainly one method which reads the dialog control info from a file - the text, color, font, position, etc. So all of that code fits nicely in my base class, and from the outside I just need to call a generic LoadFromFile method, and the class does everything. The descendant classes can override this method to add any special items, like a flag for a checkbox for instance.

There are some other basic methods, like adding a bitmap, which one control might handle differently than another.

My solution to use GetCWnd() method to get the class ptr I need is not so bad. The thing I'm more unhappy about is not being able to implement message handlers such as CtlColor and OnSetCursor in the base class. If I've got 5 control classes, now I have 5 copies of the same handlers. I loathe redundant code, it keeps me up at night. :)</description>
		<content:encoded><![CDATA[<p>Well, yeah, the virtual base class is what would make this work, but the problem is you get compile errors because of how MFC is implemented (something to do with the message mapping). That was one of the articles I linked (the one that says MI is not required for serious applications).</p>
<p>The reason I want to do it this way, is because 95% of the code for my control class is the same. It&#8217;s mainly one method which reads the dialog control info from a file - the text, color, font, position, etc. So all of that code fits nicely in my base class, and from the outside I just need to call a generic LoadFromFile method, and the class does everything. The descendant classes can override this method to add any special items, like a flag for a checkbox for instance.</p>
<p>There are some other basic methods, like adding a bitmap, which one control might handle differently than another.</p>
<p>My solution to use GetCWnd() method to get the class ptr I need is not so bad. The thing I&#8217;m more unhappy about is not being able to implement message handlers such as CtlColor and OnSetCursor in the base class. If I&#8217;ve got 5 control classes, now I have 5 copies of the same handlers. I loathe redundant code, it keeps me up at night. <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Ballman</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-20</link>
		<dc:creator>Aaron Ballman</dc:creator>
		<pubDate>Fri, 12 Oct 2007 15:17:43 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-20</guid>
		<description>Last thing first: check out this link to MSDN, specifically the Virtual and Nonvirtual Inheritance section.

http://msdn2.microsoft.com/en-us/library/wcz57btd(VS.80).aspx

I finally think I understand what you're after now though.  :-)  You have a bunch of CWnd controls (like CEdit, CButton, etc), but you also want them to inherit from your common set of "Control" functionality.  But your Control functionality wants to be a CWnd as well so it can manipulate the control as a base window object.  However, you can't make Control inherit from CWnd because of multiple vtables.  Basically correct?</description>
		<content:encoded><![CDATA[<p>Last thing first: check out this link to MSDN, specifically the Virtual and Nonvirtual Inheritance section.</p>
<p><a href="http://msdn2.microsoft.com/en-us/library/wcz57btd" rel="nofollow">http://msdn2.microsoft.com/en-us/library/wcz57btd</a>(VS.80).aspx</p>
<p>I finally think I understand what you&#8217;re after now though.  <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You have a bunch of CWnd controls (like CEdit, CButton, etc), but you also want them to inherit from your common set of &#8220;Control&#8221; functionality.  But your Control functionality wants to be a CWnd as well so it can manipulate the control as a base window object.  However, you can&#8217;t make Control inherit from CWnd because of multiple vtables.  Basically correct?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Zitomer</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-19</link>
		<dc:creator>Bill Zitomer</dc:creator>
		<pubDate>Fri, 12 Oct 2007 06:34:12 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-19</guid>
		<description>Well, no that's not what I was after. What I want is to avoid rewriting methods that already exist. All of the stuff that already exists in CWnd, I just want to be able to call it, directly. 

My classes are simple:

class CMyControl : virtual public CWnd {…}

class CMyEdit : public CEdit, public CMyControl {…}

The class that uses CMyControl (a dialog class, go figure) doesn't need to know if it's an edit control, or a checkbox control, or what. It just needs to know that it's a "contorl" and it can go ahead and position it, or set its font, or change its color, etc. The descendant classes to CMyControl - like CMyEdit - will implement those functions. I don't need to worry about it, because the underlying MFC controls already do those things. But, if I'm the dialog class and all I have is a pointer to CMyControl, then I need to get a hold of a pointer to the CWnd object to do those things.

Also, I don't think you're last statement is correct. Delcaring a pure virtual base class (I believe) is just like declaring a virtual method in a base class. Once you've done it, the descendants are automatically virtual whether you use the keyword or not.</description>
		<content:encoded><![CDATA[<p>Well, no that&#8217;s not what I was after. What I want is to avoid rewriting methods that already exist. All of the stuff that already exists in CWnd, I just want to be able to call it, directly. </p>
<p>My classes are simple:</p>
<p>class CMyControl : virtual public CWnd {…}</p>
<p>class CMyEdit : public CEdit, public CMyControl {…}</p>
<p>The class that uses CMyControl (a dialog class, go figure) doesn&#8217;t need to know if it&#8217;s an edit control, or a checkbox control, or what. It just needs to know that it&#8217;s a &#8220;contorl&#8221; and it can go ahead and position it, or set its font, or change its color, etc. The descendant classes to CMyControl - like CMyEdit - will implement those functions. I don&#8217;t need to worry about it, because the underlying MFC controls already do those things. But, if I&#8217;m the dialog class and all I have is a pointer to CMyControl, then I need to get a hold of a pointer to the CWnd object to do those things.</p>
<p>Also, I don&#8217;t think you&#8217;re last statement is correct. Delcaring a pure virtual base class (I believe) is just like declaring a virtual method in a base class. Once you&#8217;ve done it, the descendants are automatically virtual whether you use the keyword or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Ballman</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-18</link>
		<dc:creator>Aaron Ballman</dc:creator>
		<pubDate>Fri, 12 Oct 2007 06:09:38 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-18</guid>
		<description>Yeah, I just re-read your post -- I think my cold is getting the better of me.  ;-)  I think the nomenclature was what tripped me up since you described interfaces in the context of multiple inheritance.

You're right that what you were describing was an interface, but I think you got the syntax slightly wrong.  Simply declaring the class as virtual doesn't make it pure virtual, which is what's needed to make an interface in C++.

What I *think* (and I could be off-base!) you're looking for is something more like this:
&lt;code&gt;
class MyControl {
  virtual void MoveWindow( ... ) = 0L;
  virtual void Blah( ... ) = 0L;
};

class MyAwesomeEdit : public CEdit, public MyControl {
  ...
};&lt;/code&gt;

This would allow you to pass things around as MyControl (generically), but still have concrete MFC objects under the hood.  However, I may not be understanding exactly what you're after either (damned cold!).

Oh, and another interesting thing to note: unless CEdit also declares that it inherits CWnd virtually, then you will still end up with two vtables in your CEdit subclass -- one virtual, the other not.  Goes to show just how evil multiple inheritance really is.  :-P</description>
		<content:encoded><![CDATA[<p>Yeah, I just re-read your post &#8212; I think my cold is getting the better of me.  <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  I think the nomenclature was what tripped me up since you described interfaces in the context of multiple inheritance.</p>
<p>You&#8217;re right that what you were describing was an interface, but I think you got the syntax slightly wrong.  Simply declaring the class as virtual doesn&#8217;t make it pure virtual, which is what&#8217;s needed to make an interface in C++.</p>
<p>What I *think* (and I could be off-base!) you&#8217;re looking for is something more like this:<br />
<code><br />
class MyControl {<br />
  virtual void MoveWindow( ... ) = 0L;<br />
  virtual void Blah( ... ) = 0L;<br />
};</p>
<p>class MyAwesomeEdit : public CEdit, public MyControl {<br />
  ...<br />
};</code></p>
<p>This would allow you to pass things around as MyControl (generically), but still have concrete MFC objects under the hood.  However, I may not be understanding exactly what you&#8217;re after either (damned cold!).</p>
<p>Oh, and another interesting thing to note: unless CEdit also declares that it inherits CWnd virtually, then you will still end up with two vtables in your CEdit subclass &#8212; one virtual, the other not.  Goes to show just how evil multiple inheritance really is.  <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Zitomer</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-16</link>
		<dc:creator>Bill Zitomer</dc:creator>
		<pubDate>Fri, 12 Oct 2007 05:31:22 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-16</guid>
		<description>I never said COM was based on MI, just that it's a horrible construct. But so is MFC. ;) 

An interface is exactly what GetCWnd is. My problem is that writing somecontrol.GetCWnd()-&gt;MoveWindow(here) is far more ugly than somecontrol.MoveWindow(here). 

COM is a whole other can of worms. Now you've got to CoCreateInstance and QueryInterface your way through nested if's and hope your programmers are checking their returns, and freeing their bstrs and such, and fixing their cut-and-pasted sample code because 98% of it is wrong! 

And tell me again how I can implement a CtlColor handler ONCE, for all 5 of my control classes?</description>
		<content:encoded><![CDATA[<p>I never said COM was based on MI, just that it&#8217;s a horrible construct. But so is MFC. <img src='http://zitomerconsulting.com/WordPress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>An interface is exactly what GetCWnd is. My problem is that writing somecontrol.GetCWnd()->MoveWindow(here) is far more ugly than somecontrol.MoveWindow(here). </p>
<p>COM is a whole other can of worms. Now you&#8217;ve got to CoCreateInstance and QueryInterface your way through nested if&#8217;s and hope your programmers are checking their returns, and freeing their bstrs and such, and fixing their cut-and-pasted sample code because 98% of it is wrong! </p>
<p>And tell me again how I can implement a CtlColor handler ONCE, for all 5 of my control classes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Ballman</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-13</link>
		<dc:creator>Aaron Ballman</dc:creator>
		<pubDate>Fri, 12 Oct 2007 01:30:17 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-13</guid>
		<description>"Are you kidding me?! That’s a rather condescending remark to say the least, especially from the folks who brought us COM!"

COM doesn't use multiple inheritance... it uses multiple interface implementations.  COM is simply a set of interfaces, the concrete classes implement those.  Just because a class implements multiple interfaces doesn't mean it has multiple vtables.  You don't hit that until you get into the really crazy stuff like aggregates, inner and outer objects and the like.  And they're right, multiple inheritance is almost never needed in the real world, which is why you see a lot of languages going away from it.

Why aren't you using interfaces instead of trying to jam multiple inheritance into the picture?  It sounds like you just want to have all these classes implement a base subset of functionality, while still being concrete instances of their proper classes.  So, for instance, all controls can set their position and size, and you want to reference that in a generic fashion.  So make an interface which exposes that functionality generically, and be done with it.  It makes no sense for a control to be both a CWnd and a CSomeOtherControl...</description>
		<content:encoded><![CDATA[<p>&#8220;Are you kidding me?! That’s a rather condescending remark to say the least, especially from the folks who brought us COM!&#8221;</p>
<p>COM doesn&#8217;t use multiple inheritance&#8230; it uses multiple interface implementations.  COM is simply a set of interfaces, the concrete classes implement those.  Just because a class implements multiple interfaces doesn&#8217;t mean it has multiple vtables.  You don&#8217;t hit that until you get into the really crazy stuff like aggregates, inner and outer objects and the like.  And they&#8217;re right, multiple inheritance is almost never needed in the real world, which is why you see a lot of languages going away from it.</p>
<p>Why aren&#8217;t you using interfaces instead of trying to jam multiple inheritance into the picture?  It sounds like you just want to have all these classes implement a base subset of functionality, while still being concrete instances of their proper classes.  So, for instance, all controls can set their position and size, and you want to reference that in a generic fashion.  So make an interface which exposes that functionality generically, and be done with it.  It makes no sense for a control to be both a CWnd and a CSomeOtherControl&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-11</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Fri, 12 Oct 2007 01:09:06 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-11</guid>
		<description>lol. Don't worry, I grafted the good parts.</description>
		<content:encoded><![CDATA[<p>lol. Don&#8217;t worry, I grafted the good parts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-9</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 12 Oct 2007 00:01:57 +0000</pubDate>
		<guid>http://zitomerconsulting.com/WordPress/2007/10/11/mfc-and-multiple-inheritance/#comment-9</guid>
		<description>oh no! you are getting rid of my lovely checkbox and label classes!!</description>
		<content:encoded><![CDATA[<p>oh no! you are getting rid of my lovely checkbox and label classes!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
