저는 class
을 가지고 있습니다.이 객체는 기본적으로 다른 객체에 대한 포인터 인 2D matrix
의 래퍼이고의 행렬입니다. 내 class
의 소멸자가 호출 될 때마다 어떤 이유 포인터의 벡터 행렬을 사용하여 객체에서 소멸자를 호출 할 때 프로그램이 충돌합니다
nullptr
을 경우에도
delete
포인터를 시도처럼 보인다.
CPP 파일 :
RotationSolution.h
:
#ifndef PUZZLESOLVER_ROTATIONSOLUTION_H
#define PUZZLESOLVER_ROTATIONSOLUTION_H
#include <vector>
#include <fstream>
#include "PuzzlePiece.h"
using namespace std;
class RotationSolution {
private:
int _height, _width;
vector<vector<PuzzlePiece*>> _matrix;
public:
RotationSolution();
RotationSolution(int height, int width);
vector<PuzzlePiece*>& operator[](int row);
int get_height() const;
int get_width() const;
};
#endif //PUZZLESOLVER_ROTATIONSOLUTION_H
RotationSolution.cpp :
#include "RotationSolution.h"
vector<PuzzlePiece*>& RotationSolution::operator[](int row) {
return _matrix[row];
}
RotationSolution::RotationSolution() : RotationSolution(0, 0) {}
RotationSolution::RotationSolution(int height, int width) :
_height(height), _width(width), _matrix(vector<vector<PuzzlePiece*>>(_height, vector<PuzzlePiece*>(_width, nullptr)))
{}
int RotationSolution::get_height() const {
return _height;
}
int RotationSolution::get_width() const {
return _width;
}
다음
내
.h
및
.cpp
파일입니다 0
코드는 실제로 다음과 같습니다 섹션에서 충돌한다 :
for (auto length: _rowLengths) {
auto height = size/length;
_sol = RotationSolution(height, length);
...
}
을 _sol = RotationSolution(height, length);
라인의 두 번째 반복에서.
// __p is not permitted to be a null pointer.
void
deallocate(pointer __p, size_type)
{ ::operator delete(__p); }
내가 지금 어떤 멍청한 놈의 실수를 용서하시기 바랍니다 c++
새로운 여전히 오전 :
디버깅의 코드는 충돌 신호 (lib 디렉토리 파일을 인 내가 확신) new_allocator.h
에서입니다 전송 나쁜 사례 :)
왜 downvote? 누락 된 것이 있으면 알려주세요. –
코드를 모두 붙여 놓으셨습니까? 소멸자조차도 가지고 있지 않습니다. 어떻게 거기에서 충돌 할 수 있습니까? – nvoigt
[mcve]를 게시하십시오. – nvoigt