Это мое определение класса и только конструктор копирования из более крупной программы. Когда мой деструктор выполнит, будет ли он автоматически освобождать память «coeff»? Я считаю, что, однако, моя программа выдает ошибку _CrtIsValidHeapPointer (pUserData) после завершения программы.Что происходит с новыми конструкторами классов?
class Poly
{
private:
int order; //order of the polynomial
int size; //order + 1
int * coeff;//pointer to array of coeff on the heap
public:
Poly();
Poly(int Order);
Poly(int Order, int * Coeff);
~Poly(){cout << "Destructor\n";};
Poly(const Poly &rhs);
//accessors & mutators
void set();
void set(int * Coeff, int Order);
int getorder(){return order;};
int * get()const{return coeff;};
//Overloaded Operators
Poly operator+(const Poly &rhs);
Poly operator-(const Poly &rhs);
Poly operator*(const int scale);
Poly operator=(const Poly &rhs);
Poly operator*(const Poly &rhs);
const int& operator[](int I)const;
int& operator[](int I);
bool operator==(const Poly &rhs);
int operator()(int X);
friend ostream & operator<<(ostream & Out, const Poly &rhs);
friend istream & operator >>(istream & In, Poly &rhs);
};
Poly::Poly(const Poly &rhs)
{
order = rhs.order;
size = rhs.size;
int *coeff = new int[size];
for(int i(0); i <= order; i++)
coeff[i] = rhs.coeff[i];
}
Благодаря
Нет, ваш деструктор ничего не выпускает. – juanchopanza