Why am I getting a heap error error?

I am new to C ++. I get a HEAP CORRUPTION ERROR. Any help would be greatly appreciated. Below is my code

class CEntity  
{  
//some member variables  
CEntity(string section1,string section2);  
CEntity();  
virtual ~CEntity();  
//pure virtual function ..  
virtual CEntity* create()const = 0;  
};  

I get CLine from CEntity as below

class CLine:public CEntity  
{  
// Again some variables ...  
// Constructor and destructor  
CLine(string section1,string section2);  
CLine();  
~CLine();  
CLine* Create() const;  
}  

// CLine Implementation  
CLine::CLine(string section1,string section2) : CEntity(section1,section2){};  
CLine::CLine();  
CLine* CLine::create() const {return new CLine();}  

I have another CReader class that uses a CLine object and populates it as a multimap, as shown below

class CReader  
{  
public:  
CReader();  
~CReader();  
multimap<int,CEntity*>m_data_vs_entity;  
};  

//CReader Implementation  
CReader::CReader()  
{  
  m_data_vs_entity.clear();  
};  

CReader::~CReader()  
{  
  multimap<int,CEntity*>::iterator iter;  
  for(iter = m_data_vs_entity.begin();iter!=m_data_vs_entity.end();iter++)  
  {  
    CEntity* current_entity = iter->second;  
    if(current_entity)  
      delete current_entity;  
  }  
  m_data_vs_entity.clear();  
}  

, CLine. CReader. CEntity , , CReader . , , HEAP CORRUPTION ERROR . - , , , , , . ,
,
Atul

Y'day: , , , - , . , .

CEntity::CEntity(string section1,string section2)
{
    size_t length;
    char buffer[9];
    //Entity Type Number
    length = section1.copy(buffer,8,0);
    buffer[length]='\0';
    m_entity_type = atoi(buffer);

    //Parameter Data Count
    length = section1.copy(buffer,8,8);
    buffer[length]='\0';
    m_param_data_pointer = atoi(buffer);
        //.... like wise ....
}

8 , '\ 0', , , , .

: (XXX) XXX CRT , .. , - , . , - , . ,

+3
2

, , . - , .
:
1. , .
2. - . , , . 3. , , .

:)
,

0

, .

, CLine CReader?

, "" CEntity? , "" , ...

:

", CEntitys , . , ."

, CEntities, , ...

+1

Source: https://habr.com/ru/post/1736982/


All Articles