Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 25th, 2006, 08:15 PM
Lynn McGuire
Guest
 
Posts: n/a
Default multiple inheritence contructor

Is there anything special about building a constructor in a class
with two base classes ? I am having a memory issue with something
like the following code:

class ViewSummary : public CDialog, public DesDialog
{
// Construction
public:
ViewSummary(CWnd* pParent = NULL); // standard constructor
.... more declarations ...
}

ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
: CDialog(ViewSummary::IDD, pParent), DesDialog()
{
... some code ...
}

Thanks for any ideas,
Lynn


  #2  
Old January 25th, 2006, 08:15 PM
Alf P. Steinbach
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

* Lynn McGuire:[color=blue]
> Is there anything special about building a constructor in a class
> with two base classes ? I am having a memory issue with something
> like the following code:
>
> class ViewSummary : public CDialog, public DesDialog
> {
> // Construction
> public:
> ViewSummary(CWnd* pParent = NULL); // standard constructor
> ... more declarations ...
> }
>
> ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
> : CDialog(ViewSummary::IDD, pParent), DesDialog()
> {
> ... some code ...
> }
>
> Thanks for any ideas,[/color]

There is a possibility that you are inheriting twice from the same base
class, which, if so, could perhaps lead to trouble.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
  #3  
Old January 25th, 2006, 08:28 PM
Axter
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

Lynn McGuire wrote:[color=blue]
> Is there anything special about building a constructor in a class
> with two base classes ? I am having a memory issue with something
> like the following code:
>
> class ViewSummary : public CDialog, public DesDialog
> {
> // Construction
> public:
> ViewSummary(CWnd* pParent = NULL); // standard constructor
> ... more declarations ...
> }
>
> ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
> : CDialog(ViewSummary::IDD, pParent), DesDialog()
> {
> ... some code ...
> }
>
> Thanks for any ideas,
> Lynn[/color]

Try using virtual inheritance

  #4  
Old January 25th, 2006, 08:35 PM
Shark
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

Lynn McGuire wrote:[color=blue]
> Is there anything special about building a constructor in a class
> with two base classes ? I am having a memory issue with something
> like the following code:
>
> class ViewSummary : public CDialog, public DesDialog
> {
> // Construction
> public:
> ViewSummary(CWnd* pParent = NULL); // standard constructor
> ... more declarations ...
> }
>
> ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
> : CDialog(ViewSummary::IDD, pParent), DesDialog()
> {
> ... some code ...
> }
>
> Thanks for any ideas,
> Lynn[/color]

If both those base classes have some common member functions that you
are using in your derived class it will lead to ambiguity and therefore
you might consider either using the scope operator:

using CDialog::Blah1()
using DesDialog::Blah2()

or making them both virtual base classes (not abstract base classes!)

class ViewSummary : virtual public CDialog, virtual public DesDialog

in which case you don't need the scope operator.

  #5  
Old January 25th, 2006, 08:45 PM
Lynn McGuire
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

> There is a possibility that you are inheriting twice from the same base[color=blue]
> class, which, if so, could perhaps lead to trouble.[/color]

CDialog and DesDialog are totally different class structures.

CDialog is a child of CWnd is a child of CCmdTarget is a child of
CObject (base class).

DesDialog is a child of FmDialog is a child of XDialog is a child of
DialogObject is a child of WindowsObject is a child of ObjPtr (base
class).

Thanks,
Lynn


  #6  
Old January 25th, 2006, 09:35 PM
Stephan Brönnimann
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

Lynn McGuire wrote:[color=blue]
> Is there anything special about building a constructor in a class
> with two base classes ? I am having a memory issue with something
> like the following code:
>
> class ViewSummary : public CDialog, public DesDialog
> {
> // Construction
> public:
> ViewSummary(CWnd* pParent = NULL); // standard constructor
> ... more declarations ...
> }
>
> ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
> : CDialog(ViewSummary::IDD, pParent), DesDialog()[/color]
no need to default initialize DesDialog
[color=blue]
> {
> ... some code ...
> }
>
> Thanks for any ideas,
> Lynn[/color]

The code you have posted seems correct, what is the memory problem?
Regards, Stephan

  #7  
Old January 25th, 2006, 09:35 PM
Lynn McGuire
Guest
 
Posts: n/a
Default Re: multiple inheritence contructor

> Is there anything special about building a constructor in a class[color=blue]
> with two base classes ? I am having a memory issue with something
> like the following code:
>
> class ViewSummary : public CDialog, public DesDialog
> {
> // Construction
> public:
> ViewSummary(CWnd* pParent = NULL); // standard constructor
> ... more declarations ...
> }
>
> ViewSummary::ViewSummary(CWnd* pParent /*=NULL*/)
> : CDialog(ViewSummary::IDD, pParent), DesDialog()
> {
> ... some code ...
> }[/color]

Fixed !

I had a problem with using the correct viewsumm.h file from another
project.

Sigh. The code was correct, just the file include directives were in
error. Hard coding file pointers is *always* a bad thing.

Thanks for the ideas,
Lynn


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles