自己定义了一个自定义类
#pragma once
class CMyFriend :public CObject
{
DECLARE_SERIAL(CMyFriend)
public:
int index;
UINT QQnumber;
CString nickname;
CString realname;
DWORD IPaddress;
int Sex;
int HeadIndex;
CMyFriend();
virtual ~CMyFriend();
CMyFriend* operator=(const CMyFriend * Mfriend);
};
用其对象填充CArray对象 typedef CArray<CMyFriend,CMyFriend&> FriendArray;
FriendArray m_FArray;void CDialogBarDoc::OnFriendAdd()
{
CAddFriendDlg *pAddDlg=new CAddFriendDlg;
CMyFriend *newFriend=new CMyFriend;
CString str;if(IDOK==(pAddDlg->DoModal()))
{
if((pAddDlg->m_strNickname!="")||(pAddDlg->m_strRealname!="")
||(pAddDlg->m_Sex!=-1))
{
newFriend->nickname=pAddDlg->m_strNickname;
newFriend->realname=pAddDlg->m_strRealname;
newFriend->QQnumber=pAddDlg->m_uQQNumber;
newFriend->Sex=pAddDlg->m_Sex;
newFriend->IPaddress=pAddDlg->m_IPAdd;
newFriend->HeadIndex=pAddDlg->m_HeadIndex;
m_FArray.Add(*newFriend);
FileWrite();}else
AfxMessageBox("用户信息不全,添加好友失败!");
}
}
出现了访问冲突:DialogBar.exe 中的 0x6e656972 处最可能的异常: 0xC0000005: 读取位置 0x6e656972 时发生访问冲突 。
CArray<TYPE, ARG_TYPE>::~CArray()
{
ASSERT_VALID(this); if (m_pData != NULL)
{
for( int i = 0; i < m_nSize; i++ )
---------->       (m_pData + i)->~TYPE();
delete[] (BYTE*)m_pData;
}
}
我估计问题出在CMyFriend类的析构上,但不知道怎么办

解决方案 »

  1.   

    CMyFriend和CAddFriendDlg的实现没有贴上来不好判断问题出现在哪里。
      

  2.   

    #pragma once
    class CMyFriend :public CObject
    {
    DECLARE_SERIAL(CMyFriend)
    public:
    int index;
    UINT QQnumber;
    CString nickname;
    CString realname;
    DWORD IPaddress;
    int Sex;
    int HeadIndex;
    public: CMyFriend();
    virtual ~CMyFriend();
    CMyFriend* operator=(const CMyFriend * Mfriend);
    };
    /////////////////////
    #include "StdAfx.h"
    #include ".\myfriend.h"
    IMPLEMENT_SERIAL(CMyFriend, CObject,1)
    CMyFriend::CMyFriend(void)
    {
    }CMyFriend::~CMyFriend(void)
    {}
    CMyFriend* CMyFriend::operator = (const CMyFriend* Mfriend)
    {
    index = Mfriend->index;
        QQnumber = Mfriend->QQnumber;
        nickname = Mfriend->nickname;
        realname = Mfriend->realname;
        IPaddress = Mfriend->IPaddress;
        Sex = Mfriend->Sex;
        HeadIndex = Mfriend->HeadIndex;
        return this;}
    \\\\\\\\\\\\\\\\\\\
    #pragma once
    // CAddFriendDlg 对话框class CAddFriendDlg : public CDialog
    {
    DECLARE_DYNAMIC(CAddFriendDlg)public:
    CAddFriendDlg(CWnd* pParent = NULL);   // 标准构造函数
    virtual ~CAddFriendDlg();// 对话框数据
    enum { IDD = IDD_DIALOG1 };protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持 DECLARE_MESSAGE_MAP()
    public:
    CString m_strNickname;
    CString m_strRealname;
    UINT m_uQQNumber;
    int m_Sex;
    DWORD m_IPAdd;
    virtual BOOL OnInitDialog();
    CComboBoxEx m_ImageList;
    int m_HeadIndex;
    protected:
    afx_msg void OnSelChang();
    };
    \\\\\\\\\\\\\\\\
    // AddFriendDlg.cpp : 实现文件
    //#include "stdafx.h"
    #include "DialogBar.h"
    #include "AddFriendDlg.h"
    #include ".\addfrienddlg.h"
    #include "MainFrm.h"
    // CAddFriendDlg 对话框IMPLEMENT_DYNAMIC(CAddFriendDlg, CDialog)
    CAddFriendDlg::CAddFriendDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CAddFriendDlg::IDD, pParent)
    , m_strNickname(_T(""))
    , m_strRealname(_T(""))
    , m_uQQNumber(0)
    , m_Sex(0)
    , m_IPAdd(0)
    {
    m_HeadIndex=9;
    }CAddFriendDlg::~CAddFriendDlg()
    {
    }void CAddFriendDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT_NICKNAME, m_strNickname);
    DDV_MaxChars(pDX, m_strNickname, 20);
    DDX_Text(pDX, IDC_EDIT_REALNAME, m_strRealname);
    DDX_Text(pDX, IDC_EDIT_QQNUMBER, m_uQQNumber);
    DDX_CBIndex(pDX, IDC_COMBO_SEX, m_Sex);
    DDX_IPAddress(pDX, IDC_IPADDRESS, m_IPAdd);
    }
    BEGIN_MESSAGE_MAP(CAddFriendDlg, CDialog)
    ON_CBN_SELCHANGE(IDC_IMAGELIST,OnSelChang)
    END_MESSAGE_MAP()
    // CAddFriendDlg 消息处理程序BOOL CAddFriendDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); ((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->InsertString(0,"男");
    ((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->InsertString(1,"女");
    m_ImageList.Create(WS_CHILD|CBS_DROPDOWNLIST,
    CRect(90,170,160,350),this,IDC_IMAGELIST);

    m_ImageList.SetImageList(&((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_DialogBar.m_ImageList);
    m_ImageList.ShowWindow(TRUE);

    COMBOBOXEXITEM comboItem;
    comboItem.cchTextMax=6;
    comboItem.mask=CBEIF_IMAGE|CBEIF_SELECTEDIMAGE;

    for(int i=0;i<12;i++)
    {
    comboItem.iItem=i;
    comboItem.iImage=i;
    comboItem.iSelectedImage=i;
    comboItem.pszText="ho";
    comboItem.iOverlay=i;
    comboItem.iIndent=i;
    m_ImageList.InsertItem(&comboItem); }
    m_ImageList.SetCurSel(9);

    return TRUE; 
    // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
    }
    void CAddFriendDlg::OnSelChang()
    {
    m_HeadIndex=m_ImageList.GetCurSel();
    }