注册 登录
编程论坛 VC++/MFC

MFC中的问题

zhengjun19 发布于 2011-11-15 21:51, 738 次点击
// Demo1Doc.cpp : implementation of the CDemo1Doc class
//

#include "stdafx.h"
#include "Demo1.h"

#include "Demo1Doc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDemo1Doc

IMPLEMENT_DYNCREATE(CDemo1Doc, CDocument)

BEGIN_MESSAGE_MAP(CDemo1Doc, CDocument)
    //{{AFX_MSG_MAP(CDemo1Doc)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemo1Doc construction/destruction

CDemo1Doc::CDemo1Doc()
{
    // TODO: add one-time construction code here
     m_dib = new ImageDib;
}

CDemo1Doc::~CDemo1Doc()
{
    if(m_dib != NULL)
    {
        delete m_dib;
        m_dib = 0;

    }
}

BOOL CDemo1Doc::OnNewDocument()
{
    if (!CDocument::OnNewDocument())
        return FALSE;

    // TODO: add reinitialization code here
    // (SDI documents will reuse this document)

    return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDemo1Doc serialization

void CDemo1Doc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        // TODO: add storing code here
    }
    else
    {
        // TODO: add loading code here
    }
}

/////////////////////////////////////////////////////////////////////////////
// CDemo1Doc diagnostics

#ifdef _DEBUG
void CDemo1Doc::AssertValid() const
{
    CDocument::AssertValid();
}

void CDemo1Doc::Dump(CDumpContext& dc) const
{
    CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDemo1Doc commands

BOOL CDemo1Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
    if (m_dib.Read(lpszPathName) == TRUE)
    {
        SetModifiedFlag(FALSE);
        return FALSE;
    }
    else
   
    return 0;
}

BOOL CDemo1Doc::OnSaveDocument(LPCTSTR lpszPathName)
{
    if(m_dib.Write(lpszPathName)==TRUE)
    {
        SetModifiedFlag(FALSE);
        return TRUE;
    }
    else
        return 0;
}
红的地方报这些错误:\image\imagecpp\Demo2\Demo1Doc.cpp(33) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class ImageDib *' (or there is no acceptable conversion)
E:\image\imagecpp\Demo2\Demo1Doc.cpp(38) : error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'class ImageDib' (or there is no acceptable conversion)
E:\image\imagecpp\Demo2\Demo1Doc.cpp(40) : error C2440: 'delete' : cannot convert from 'class ImageDib' to ''
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\image\imagecpp\Demo2\Demo1Doc.cpp(40) : fatal error C1903: unable to recover from previous error(s); stopping compilation
如何修改呀?好多不懂的 请高手解答
3 回复
#2
ligl2011-11-16 10:02
如果你是定义的类对象的指针的话,就要new和delete操作!
#3
chengj2011-11-17 18:01
学习了
#4
CrystalFan2011-11-19 18:54
这个很明显是你m_dib的声明有问题:
你定义的是:
ImageDib m_dib;
应该定义:
ImageDib* m_dib;
不过最好定义成:
ImageDib* m_pDib;
1