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 | | | | 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? | | | | 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 | | | | 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. | | | | 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 | | | | 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 | | | | 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 |  | | | | /bytes/about
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 226,295 network members.
|