到底m_pCurFont=new CFont;这个定义有什么错误?系统报出一大堆错啊! 是不是定义CFont的话需要包含什么头文件的啊?不只到有没有漏掉! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 系统报出的错误如下D:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(37) : error C2065: 'm_pCurFont' : undeclared identifier CFont * m_pCurFont=new CFont(...........) 但是问题还是没解决,我贴源码出来给大家看看,大家帮我看看那里出了问题!下面这些是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_FILEstatic 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 _DEBUGvoid 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 identifierD:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(43) : error C2541: delete : cannot delete objects that are not pointersD:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(115) : error C2541: delete : cannot delete objects that are not pointersD:\Program Files\Microsoft Visual Studio\MyProjects\showmap1\showmap1View.cpp(117) : error C2227: left of '->CreateFontA' must point to class/struct/unionError executing cl.exe.showmap1.exe - 4 error(s), 0 warning(s)大家帮我看看问题到底是出在那里? 你的CFont * m_pCurFont=new CFont;应该是不对的m_pCurFont应该作为一个成员变量你在构造里面定义是不可以的变量生命空间问题 thanks 问题解决了,原来我在类说明那里定义变量的时候把变量名字给写错拉~ qq是怎么实现发送文件时显示文件的类型图标 和文件名的???????????????? 怎么让RichEdit控件只能输入数字 爱情与生活! 串口 造成系统重起(解决另外放风500) 如何编程实现三维图象 1000分的小问题,竟然没人愿意要 跨系统两进程通信copydata接收显示乱码 高手请进,如何解决这个关于多重继承与静态cast的问题 请问StrTrim() 文本格式修正软件 关于MSVCRT.DLL和MSVCRTD.DLL的疑惑?? 大家来看看VC出现下面这个提示怎么解决
//#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)
大家帮我看看问题到底是出在那里?
应该是不对的
m_pCurFont
应该作为一个成员变量
你在构造里面定义是不可以的
变量生命空间问题