是不是定义CFont的话需要包含什么头文件的啊?不只到有没有漏掉!

解决方案 »

  1.   

    系统报出的错误如下D:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(37) : error C2065: 'm_pCurFont' : undeclared identifier
      

  2.   

    CFont * m_pCurFont=new CFont(...........)
      

  3.   

    但是问题还是没解决,我贴源码出来给大家看看,大家帮我看看那里出了问题!下面这些是Cshowmapview类:// showmap1View.cpp : implementation of the CShowmap1View class
    //#include "stdafx.h"
    #include "showmap1.h"#include "showmap1Doc.h"
    #include "showmap1View.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CShowmap1ViewIMPLEMENT_DYNCREATE(CShowmap1View, CView)BEGIN_MESSAGE_MAP(CShowmap1View, CView)
    //{{AFX_MSG_MAP(CShowmap1View)
    ON_COMMAND(DIB_READ, OnRead)
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CShowmap1View construction/destructionCShowmap1View::CShowmap1View()
    {
    // TODO: add construction code here
        CFont * m_pCurFont=new CFont;
        m_pCurFont->CreateFont(40,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH&FF_SWISS,"Aerial");
    }CShowmap1View::~CShowmap1View()
    {
    delete m_pCurFont;
    }BOOL CShowmap1View::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
    }/////////////////////////////////////////////////////////////////////////////
    // CShowmap1View drawingvoid CShowmap1View::OnDraw(CDC* pDC)
    {
    CShowmap1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    Redraw(pDC);
    // TODO: add draw code for native data here
    }/////////////////////////////////////////////////////////////////////////////
    // CShowmap1View printingBOOL CShowmap1View::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
    return DoPreparePrinting(pInfo);
    }void CShowmap1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add extra initialization before printing
    }void CShowmap1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add cleanup after printing
    }/////////////////////////////////////////////////////////////////////////////
    // CShowmap1View diagnostics#ifdef _DEBUG
    void CShowmap1View::AssertValid() const
    {
    CView::AssertValid();
    }void CShowmap1View::Dump(CDumpContext& dc) const
    {
    CView::Dump(dc);
    }CShowmap1Doc* CShowmap1View::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShowmap1Doc)));
    return (CShowmap1Doc*)m_pDocument;
    }
    #endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CShowmap1View message handlersvoid CShowmap1View::OnRead() 
    {
    // TODO: Add your command handler code here
    CFontDialog dlg;
    int nRet=dlg.DoModal();
    if(nRet==IDOK)
    {
    delete m_pCurFont;
    //CFont* m_pCurFont=new CFont;
    m_pCurFont->CreateFont(dlg.GetSize(),0,0,0,dlg.GetWeight(),dlg.IsItalic(),dlg.IsUnderline(),dlg.IsStrikeOut(),ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH&FF_SWISS,dlg.GetFaceName());
    m_nColor=dlg.GetColor();
    }
    CDC* pDC=GetDC();
    Redraw(pDC);
    }void CShowmap1View::Redraw(CDC *pDC)
    {
    CRect rect;
    GetClientRect(&rect);
    CBrush* pOldBrush=(CBrush *)pDC->SelectStockObject(WHITE_BRUSH);
    pDC->Rectangle(rect);
    pDC->SelectObject(pOldBrush);
    CFont* pOldFont;
    pOldFont=(CFont*)pDC->SelectObject(m_pCurFont);
    pDC->SetTextColor(m_nColor);
    pDC->TextOut(40,40,"我爱MFC编程");
    pDC->SelectObject(pOldFont);
    }
    系统报出的错误有这些:howmap1View.cpp(43) : error C2065: 'm_pCurFont' : undeclared identifier
    D:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(43) : error C2541: delete : cannot delete objects that are not pointers
    D:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(115) : error C2541: delete : cannot delete objects that are not pointers
    D:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(117) : error C2227: left of '->CreateFontA' must point to class/struct/union
    Error executing cl.exe.showmap1.exe - 4 error(s), 0 warning(s)
    大家帮我看看问题到底是出在那里?
      

  4.   

    你的CFont * m_pCurFont=new CFont;
    应该是不对的
    m_pCurFont
    应该作为一个成员变量
    你在构造里面定义是不可以的
    变量生命空间问题
      

  5.   

    thanks 问题解决了,原来我在类说明那里定义变量的时候把变量名字给写错拉~