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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
alb66Connect With a Mentor Commented:
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
 
alb66Commented:
class MySecondDialog : public MyFirstDialog
{
public:
      MySecondDialog(CWnd* pParent = NULL);   // costruttore standard
      virtual ~MySecondDialog();
}
0
 
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
All Courses

From novice to tech pro — start learning today.