Tuesday, April 10, 2012

C++ Read Access violation error

I am currently getting an "0xC0000005: Access violation reading location 0xcccccce0." error and I have tried diagnose the problem...I think the problem comes in when my rule of 3 that I have defined comes in play and points me to here.



size_type size() const
{ // return length of sequence
return (this->_Mysize); <---------------------this line
}


I'm actually not sure if there is any problem at all, I have been dwelling on this for days on end.



here is my rule of three



ArrayStorage::ArrayStorage(){
myArray = new string[7079];
}

ArrayStorage::~ArrayStorage(){
delete[] _data;
delete[] myArray;
}

ArrayStorage::ArrayStorage(const ArrayStorage &A) {
_size = A.size();
_data = new string [size()];
for (int i = 0; i < size(); ++i)
_data[i] = A[i];
}

ArrayStorage& ArrayStorage::operator=(const ArrayStorage &A){
if (this != &A) {
delete [] _data;
_size = A.size();
_data = new string [A.size()];
for (int i = 0; i < size(); ++i) {
_data[i] = A[i];
}
}
return *this;
}

const string& ArrayStorage::operator[](int i) const{
assert((i >= 0) && (i < size()));
return _data[i];
}

string& ArrayStorage::operator[](int i){
assert((i >= 0) && (i < size()));
return _data[i];
}




No comments:

Post a Comment