multiple inheritence contructor

L

Lynn McGuire

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
 
A

Alf P. Steinbach

* Lynn McGuire:
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,

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

Axter

Lynn said:
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

Try using virtual inheritance
 
S

Shark

Lynn said:
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

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.
 
L

Lynn McGuire

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

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
 
?

=?iso-8859-1?q?Stephan_Br=F6nnimann?=

Lynn said:
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()
no need to default initialize DesDialog
{
... some code ...
}

Thanks for any ideas,
Lynn

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

Lynn McGuire

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 ...
}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top