Hi Guys,
I am a newbie to c++ programming and I need help with my program. Can anybody help me out? I am trying to pass pointer to a structure to create an object. The program compiles fine but during execution I get the following error:
Debug Assertion Failed!
Program: C:\PROGRAM FILES\.....
File: dbgdel.cpp
Line: 47
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
This is visual studio .net 2003 environment.
Couple of things more: I am just starting out in C++ and any kind of feedback on the logic/design of my program is appreciated. I dont know if passing structures by reference is a good idea, please let me know how to do that. Also please ignore the mess of file input, it is for testing and unrelated (I hope) to the error. I have an idea that my delete call to destructor is causing the error, but I dont know how and how to fix it. And thanks in advance for your input.
-Sam
I tried searching the forums before posting but could not find anything.
Code:struct strArray { int size; int position; int *byteArray; }; class BinaryInputStream { protected : strArray *source; private : int i; public: BinaryInputStream(strArray *source) { this->source = source; //for (i = 0; i < source->size; i++) { i = 0; while (i < source->size) { cout << "in default constructor " << source->byteArray[i] << "\n"; i++; } } ~BinaryInputStream() { delete [] source->byteArray; delete source; } } int main(int argc, char **argv) { int i = 0, x=0; strArray *source; strArray src; source = & src; if ((argc < 2)) { cout << "\nMissing arguments\n\n"; cout << "USAGE : mre inputfilename\n\n"; return 0; } else { cout << "Hello World\n The file size is :"; ifstream inFile; inFile.open(argv[1], ios::binary); inFile.seekg(0, ios::end); i = inFile.tellg(); cout <<i << "\n"; source->byteArray = new int[i]; if (source->byteArray == NULL) { return 0; } while ((inFile.good()) && (x < i)) { source->byteArray[x] = x + 1; cout << "Byte " << x << ": " << source->byteArray[x] <<"\n"; x++; } inFile.close(); BinaryInputStream *ptr = new BinaryInputStream(source); delete ptr; } return 0; }



LinkBack URL
About LinkBacks
) to the error. I have an idea that my delete call to destructor is causing the error, but I dont know how and how to fix it. And thanks in advance for your input.


