간단한 클래스에서 new'ed 메모리에 대한 포인터를 감싸는 아주 바보 같은 실수를하고 있습니다. 내가 클래스의 인스턴스와 벡터를 채울 때new with C++ constructor
class Matrix
{
public:
Matrix(int w,int h) : width(w),height(h)
{
data = new unsigned char[width*height];
}
~Matrix() { delete data; }
Matrix& Matrix::operator=(const Matrix&p)
{
width = p.width;
height = p.height;
data= p.data;
return *this;
}
int width,height;
unsigned char *data;
}
.........
// main code
std::vector<Matrix> some_data;
for (int i=0;i<N;i++) {
some_data.push_back(Matrix(100,100)); // all Matrix.data pointers are the same
}
는 내부 데이터 포인터는 모두 같은 메모리를 가리키는 끝?
월요일에 일어나서 "나는 바보 야."라고 말하면서 고마워요 - –