Little Tooth Little Tooth - 1 year ago 76
C++ Question

C++: initial a pointer

These codes are parts of project:

//.h file


#include "filter.h"

class ImageFilter : public Filter {
ImageFilter(int _dimension);
virtual ~ImageFilter();
int* values;

//.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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download