SDI MFC VC ++中删除功能的问题 [英] Problem in delete function in SDI MFC VC++
本文介绍了SDI MFC VC ++中删除功能的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从CView继承的mfc vc ++类.
I have an mfc vc++ class which is inherited from CView
#include "NormalClass.h"
class FView : public CView
{
DECLARE_DYNCREATE (FView)
public:
FView ();
~FView ();
NormalClass *m_pcNormal;
}
在类的构造方法中,我正在将内存分配给普通的cpp类实例
In Constructor of class I am allocating memory to normal cpp class instance
FView::FView ()
{
m_pcNormal = new NormalClass[20];
}
在类的Destructor中,我正在删除cpp类的内存
In Destructor of class i am deleting the memory of cpp class
FView::~FView ()
{
if (m_pcNormal)
{
for (int i = 0; i < 20; i++)
{
delete m_pcNormal[i]; // problem is here
// it is showing expression must have pointer or handle
// it is crashing when i am doing like this delete &m_pcNormal[i];
}
delete [] m_pcNormal; m_pcNormal = NULL;
}
}
我的普通cpp课是这样的
And my normal cpp class is like this
class NormalClass
{
private:
funt1 ();
int a;
public:
NormalClass();
~NormalClass();
}
解决此问题的任何方法
Any solution for this problem
推荐答案
您正在为尚未使用new
分配的对象调用delete
.您可以将m_pcNormal
更改为NormalClass**
并为构造函数中的m_pcNormal[]
的每个元素调用new
(或以后;将元素初始化为NULL),或使用数组类进行存储.
You are callingdelete
for objects that has not been allocated usingnew
. You may changem_pcNormal
toNormalClass**
and callnew
for each element ofm_pcNormal[]
in the constructor (or later; than initialize the elements to NULL), or use an array class for storage.
这篇关于SDI MFC VC ++中删除功能的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文