Subclassing a subclassed CDialog

Hi

I have created a dialog via MFC in VS2005. I have called this MyFirstDialog. I have then created another dialog , called MySecondDialog, which I want to inherit from MyFirstDialog. I changed all instances of CDialog in MySecondDialog to MyFirstDialog but when I compile it I get the error message:

CMyFirstDialog::CMyFirstDialog : no overloaded function takes 2 arguments

I have obvioulsy missed something. Can anybody give me the steps I need to take to inherit from a dialog which has already been created.

John
IssacJonesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alb66Commented:
class MySecondDialog : public MyFirstDialog
{
public:
      MySecondDialog(CWnd* pParent = NULL);   // costruttore standard
      virtual ~MySecondDialog();
}
0
alb66Commented:
Probably the constructor of MySecondDialog lokk like this:

MySecondDialog ::MySecondDialog (CWnd* pParent /*=NULL*/)
      : MyFirstDialog(MySecondDialog ::IDD, pParent)
{
}

It calls the constructors of MyFirstDialog with two parameters: the template ID and the parent:

But the connstructor of MyFirstDialog take only one parameter, the parent:

MyFirstDialog ::MyFirstDialog (CWnd* pParent /*=NULL*/)
      : CDialog(MyFirstDialog ::IDD, pParent)
{
}

You can add a constructor to MyFirstDialog  that take 2 parameters:

MyFirstDialog ::MyFirstDialog ( int nIDD /*MyFirstDialog ::IDD*/, CWnd* pParent /*=NULL*/)
      : CDialog(nIDD, pParent)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IssacJonesAuthor Commented:
Hi alb66

I'm afraid that's what I have already. I've pasted the code for the second dialog.

John

// MySecondDialog.cpp : implementation file
//

#include "stdafx.h"
#include "VS2005MFC.h"

#include "MyFirstDialog.h"

#include "MySecondDialog.h"


// CMySecondDialog dialog

IMPLEMENT_DYNAMIC(CMySecondDialog, CMyFirstDialog)

CMySecondDialog::CMySecondDialog(CWnd* pParent /*=NULL*/)
      : CMyFirstDialog(CMySecondDialog::IDD, pParent)
{

}

CMySecondDialog::~CMySecondDialog()
{
}

void CMySecondDialog::DoDataExchange(CDataExchange* pDX)
{
      CMyFirstDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMySecondDialog, CMyFirstDialog)
END_MESSAGE_MAP()


// CMySecondDialog message handlers

*****************************************************************************************************************

#pragma once


// CMySecondDialog dialog

class CMySecondDialog : public CMyFirstDialog
{
      DECLARE_DYNAMIC(CMySecondDialog)

public:
      CMySecondDialog(CWnd* pParent = NULL);   // standard constructor
      virtual ~CMySecondDialog();

// Dialog Data
      enum { IDD = IDD_DIALOG2 };

protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

      DECLARE_MESSAGE_MAP()
};
0
IssacJonesAuthor Commented:
Hi, sorry, I didn't get your second mail until I'd sent me second post. Your solutions seems to have worked. Many thanks. john
0
alb66Commented:
The problem is that you call the constructor of the first dialog with two parameters:

CMySecondDialog::CMySecondDialog(CWnd* pParent /*=NULL*/)
      : CMyFirstDialog(CMySecondDialog::IDD, pParent)   <---- the call is here -------
{
}

but the constructor of CMyFirstDialog has only one parameter.

So, I suggested you to add a second constructor with two parameters to the first dialog:


MyFirstDialog ::MyFirstDialog ( int nIDD , CWnd* pParent )
      : CDialog(nIDD, pParent)
{
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.