내 문제를 파생 클래스 복사 생성자로 좁혔지만 원인을 알 수 없습니다. 편집 : M, N 및 데이터는 비공개입니다. 내가받는 오류는 '유효하지 않은 할당 크기 : 4294967295 바이트'입니다. 이는 -1을 new로 전달할 때 발생합니다. 나는 클래스가 comunicate 때 데이터가 손실되지 않는 한 왜 이것이 발생하는지 확신 할 수 없다.잘못된 할당 크기 (파생 클래스 복사 생성자에서)
BinaryMatrix::BinaryMatrix(const BinaryMatrix& copy) : Matrix(copy)
{
//cout << "Copy Constructor\n";
M = copy.M;
N = copy.N;
data = new double[M*N]; //This line causes the allocation error
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
data[i*N+j] = copy.data[i*N+j];
}
}
}
위의 내용은 오류의 원인이되는 파생 된 복사 생성자입니다. 나는 할당 선을 표시했다.
M 및 N이 올바르게 읽히지 않는다고 가정 할 수 있습니다. 비록 내가 왜 확신 할 수는 없지만. 파생 및 기본 생성자와 기본 복사본을 모두 포함합니다.
어떤 도움을 주셔서 감사합니다.
MATRIX (BASE) 생성자
Matrix::Matrix(int M, int N, double* input_data)
{
this->M = M;
this->N = N;
//cout << "Matrix Constructor\n";
data = new double[M*N];
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
data[i*N+j] = input_data[i*N+j];
}
}
delete [] input_data;
}
MATRIX (BASE)는 생성자
Matrix::Matrix(const Matrix& copy)
{
//cout << "Copy Constructor\n";
M = copy.M;
N = copy.N;
data = new double[M*N];
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
data[i*N+j] = copy.data[i*N+j];
}
}
}
BINARYMATRIX (파생 됨) 생성자에게 COPY
BinaryMatrix::BinaryMatrix(int M, int N, double* input_data) : Matrix(M, N, input_data)
{
data = new double[M*N];
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
this->data[i*N+j] = this->getRead(i, j);
}
}
double thr_val = this->Mean();
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (this->data[i*N+j] > thr_val)
this->data[i*N+j] = 1;
if (this->data[i*N+j] < thr_val)
this->data[i*N+j] = 0;
}
}
}
오류가 무엇입니까? – Castilho
Doh - 죄송합니다. 이제 주 질문으로 편집하겠습니다. – LBHoward
이 런타임 오류 또는 컴파일 시간 오류가 있습니까? – je4d