1,**************************************************BOOL CUDPcommApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif        //关于这句new      ************
CUDPcommDlg dlg = new CUDPcommDlg();
        //****************************************
m_pMainWnd = &dlg;
CListDlg listdlg = new CListDlg();
//m_pMainWnd = &listdlg;
//listdlg.DoModal();
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}
2************************************************************************
void CUDPcommDlg::OnSetFont() 
{
         //还有就是这个new**************************
CFontDialog chooseFont = new CFontDialog();
         //*****************************************
if(chooseFont.DoModal())
{
LOGFONT lf;     chooseFont.GetCurrentFont(&lf);     if (pfont != NULL) 
{
CFont *oldFont = pfont;
     pfont = new CFont();
         pfont->CreateFont(lf.lfHeight,lf.lfWidth,0,0,FW_THIN,FALSE,FALSE,
         0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
          1,15,lf.lfFaceName);
         SendMessageToDescendants(WM_SETFONT,(WPARAM)pfont->GetSafeHandle(),
MAKELPARAM( TRUE,0 ));
  delete(oldFont);

}
}
}报错信息:
E:\study\mywork\UDPcomm\UDPcommDlg.cpp(660) : error C2440: 'initializing' : cannot convert from 'class CFontDialog *' to 'class CFontDialog'
        No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.为什么只有第二出的new不可以?dx指点下!!!谢谢了

解决方案 »

  1.   

    因为用了快一年的java了,快把C++给忘了。第二个就算不用new,第一个也不报错,所以这才是我比较纳闷的地方!
      

  2.   

    刚才调试了一下,原来是CUDPcommDlg构造函数的问题。CUDPcommDlg dlg = new CUDPcommDlg();变成等价于CUDPcommDlg* pdlg = new CUDPcommDlg(); CUDPcommDlg dlg(pdlg); new的那个dlg作为父窗口传进去了。
      

  3.   

    我刚试了下,确实是后面new的对象作为他的另一个构造函数的参数,这种语法哪里有介绍啊,感觉比较陌生?
      

  4.   

    #include "iostream.h"
    #include "stdio.h"
    #include "string"
    using namespace std;
    class Employee{
    public:
    Employee(){cout<<"no parameter";};
    Employee(Employee* str){cout<<"self as parameter";};
    ~Employee(){};
    //virtual print(){};//cout<<"Print of Class Employee"<<endl;}private:
    char str;

    string aa;
    int  num;
    };
    struct list
    {
    char str;

    int  num;
    char str2;
    }_taglist;void main()
    {
    Employee a = new Employee();
    printf("%d\n",sizeof(a));
    printf("%d\n",sizeof(_taglist));
    //virtualPointer(&a);
    }用这个代码试验了下,构造函数确实分别被调用,谢谢tufaqing() ,马上结贴!