Click here to Skip to main content
15,741,692 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

In my Dialog based MFC application, I have the below error w.r.t Constructor, even though multiple changes made in order, and types of params, the error w.r.t constructor still exists,

class CDlgMac : public CDialog
// Construction
//  CDlgMac (CMac*,CWrkShp*,CWnd* pParent = NULL);   // standard constructor -> Scenario-I sucessfully builds with no errors.
CDlgMac (CMac*,CWrkShp*,CPtrList& ,CJoe&,CWnd* pParent = NULL); //stand
-> Scenario -II on including Class Joe and Pointer in Constructor the error is depicted.

CJoe& m_Opt;
    CPtrList& m_Obj;

In Dialog.cpp

//Adding CNewClass header file here.
#include "NewClass.h"


//CDlgMac ::CDlgMac (CMachine* pMachine,CWrkshp* pWkshp,CWnd* pParent /*=NULL*/)
// : CDialog(CDlgMac ::IDD, pParent), m_pMachine(pMachine),m_pWorkShop(pWorkShop)
// NOTE: the ClassWizard will add member initialization here

CDlgMac::CDlgMac(CMac* pMac,CWrkShp* pWrkShp,CPtrList& ObjectLst,CJoe& OptPage2 ,CWnd* pParent /*=NULL*/)
    : CDialog(CDlgMac::IDD, pParent), m_pMac(pMac),m_pWrkShp(pWrkShp),m_Obj(ObjectLst),m_Opt(OptPage2)
        // NOTE: the ClassWizard will add member initialization here


In OtherFile James.cpp

I invoke the following code,
CDlgMac dlg(pMac,m_pParent->GetWork(),NULL); ----> Error shown in this line

On build, I get the following errors,
1>error C2664: 'CDlgMac::CDlgMac(CMac *,CWrkShp *,CPtrList &,CJoe &,CWnd *)' : cannot convert parameter 3 from 'int' to 'CPtrList &'

Basically, my target is to initialize all the variables/datamembers using member initialisation lists, using pointer and class(reference).

Any help in resolving the above would be much appreciable.,
I am using VS2008IDE, MFC 9.0v.

With Regards,
Updated 27-Jul-12 3:26am

The compiler, of course is right. You cannot initialise a reference (PtrList& ObjectLst) with NULL.
Share this answer
The problem raises in the definition of the class CPtrList in list_p.cpp
CPtrList::CPtrList(INT_PTR nBlockSize)
	ASSERT(nBlockSize > 0);

	m_nCount = 0;
	m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL;
	m_pBlocks = NULL;
	m_nBlockSize = nBlockSize;

You can clearly see you cant give a value NULL to a variable of type CPtrList
Please see CObList::CObList
I know its information about other constructor but this class its almoust indentical to the CPtrList and in msdn this clas isnt documented well

CPtrList Class
I hope this information helps you
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900