dimanche 23 avril 2017

getting segmentation fault in C++ code

I am new to c++, working on my company's assignment my c++ code is giving me segmentation fault error, even debug is not detecting the exact error, please help me in this.

FetchingAndSortingFiles.h

FetchingAndSortingFiles *fileParamToSort;

FetchingAndSortingFiles.cpp

bool FetchingAndSortingFiles::mb_process()
{
---some code ---
---
fileParamToSort=new FetchingAndSortingFiles[l_unsortedFileList.size()+3];   //l_unsortedFileList.size()=3
--some code ---
--some code ---
}

in destructor in same file

 FetchingAndSortingFiles::~FetchingAndSortingFiles()
 {
   std::cout<<"fileParamToSort======="<<fileParamToSort<<std::endl;
   if(fileParamToSort){
   delete [] fileParamToSort;
   }
    fileParamToSort=NULL; 
 }

Output:

 fileParamToSort=======0x196afe8
Segmentation fault (core dumped)

Aucun commentaire:

Enregistrer un commentaire