Little Tooth Little Tooth - 16 days ago 5
C++ Question

C++: initial a pointer

These codes are parts of project:

//.h file

#ifndef IMAGEFILTER_H
#define IMAGEFILTER_H

#include "filter.h"

class ImageFilter : public Filter {
public:
ImageFilter(int _dimension);
virtual ~ImageFilter();
protected:
int* values;
};
#endif // IMAGEFILTER_H


//.cpp file

#include "imagefilter.h"

ImageFilter::ImageFilter(int _d) : Filter(_d) {
values = new int[_d * _d];
}

ImageFilter::~ImageFilter() {
delete [] values;
}


How should I understand the line :"values = new int[_d * _d];" ?
Could you help me ?

Answer

What does values = new int[_d * _d]; mean?

Reserve _d * _d of sequenced integers (probably 4 byte each) dynamically in the free store. In other words, you have reserved an array of integers with _d * _d items that can be used later in many ways.

Comments