C++ C++;:运算符重载,运算符+;

C++ C++;:运算符重载,运算符+;,c++,object,operator-overloading,C++,Object,Operator Overloading,我添加了一些注释,以便遵循这些行并找出问题所在。我没有找到导致错误的原因?您溢出了堆块 Windows has triggered a breakpoint in CNG242.exe. This may be due to a corruption of the heap, which indicates a bug in CNG242.exe or any of the DLLs it has loaded. This may also be due to the user pressing

我添加了一些注释,以便遵循这些行并找出问题所在。我没有找到导致错误的原因?

您溢出了堆块

Windows has triggered a breakpoint in CNG242.exe.
This may be due to a corruption of the heap, which indicates a bug in CNG242.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while CNG242.exe has focus.
The output window may have more diagnostic information.
这样。

表达式

coeffs = new double(size); // You allocated memory for only one double variable
为一个
double
变量分配空间,将其值初始化为
size
,并返回指向
coefs
的指针。您可能想要的是:

coeffs = new double(size);

请注意方括号。这会初始化
size
double的空间,不会将它们初始化为任何特定的值,并将指向第一个的指针返回到
coefs

您的类是否有正确的副本构造函数?请确保遵循三个规则。我真的不明白为
newPoly
使用指针的意义。只要创建一个并从每个if块返回它,或者添加/使用一个
setSize
函数。@AdamRossenfield我添加了我的复制构造函数。即使您已经解决了这个问题,您也应该修复使用
new
进行堆分配的事实,然后取消引用该指针并按值返回它。
coeffs = new double(size);
coeffs = new double[size];