Connecting Tech Pros Worldwide Help | Site Map

multiple inheritence contructor

  #1  
Old January 25th, 2006, 08:15 PM
Lynn McGuire
Guest
 
Posts: n/a
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

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

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

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

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

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

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Oriented PHP Water Cooler v2 answers 73 June 28th, 2006 03:15 PM
Declaring constructor interfaces [in interfaces] Ruffin Bailey answers 1 November 20th, 2005 02:35 PM