I am working on a class of polynomials with complex coeficients. One of constructors for this class is
I can succesfully test this constructor usingCode:poly::poly(unsigned int a, complex *b) { order = a; std::cout << "\ntestpoint4"; coef = new complex[a + 1]; std::cout << "\ntestpoint5"; for (int i = order; i >= 0; i--) { coef[i] = b[i]; } }
However, one of the methods in the polynomial class is for synthetic divisionCode:complex * tempcoefs; tempcoefs = new complex[5]; for (int j = 0; j <=4; j++) { tempcoefs[j] = complex(j,j); } poly testpoly(4,tempcoefs); testpoly.printpoly(); delete[] tempcoefs;
horner is another method in the polynomial class and is shown belowCode:poly poly::synthdiv(complex &z,complex *newcoef) { horner(z,newcoef); // now create a new array to return a new polynomial. // This loop leaves off the final output complex * newpoly = new complex[int(order)]; for (int i = 1; i <= order+1; i++) { newpoly[i-1] = newcoef[i]; } poly temp(int(order - 1),newpoly); delete[] newpoly; return temp; }
When this code is executed, the command window shows "testpoint4" but not "testpoint5" and I reach a breakpoint with the following error messageCode:void poly::horner(complex &z, complex *newcoef) { newcoef[int(order+1)] = complex(0,0); for (int i = int(order); i >= 0; i--) { newcoef[i] = coef[i+1]+z * newcoef[i+1]; } }
"Windows has triggered a breakpoint in horner.exe.
This may be due to a corruption of the heap, and indicates a bug in horner.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information"
The immediate window of the debuger shows
"HEAP[horner.exe]: Heap missing last entry in committed range near 356678"
where horner.exe is the main program that is calling the synthdiv method
Interestingly if I modify the constructor to be
I get exactly the same behavior where the synthdiv method does not work, but the test code shown at the top of this posting does. Once again, "testpoint4" shows on the command window and the now moved "testpoint5" does not. The error messages are the same.Code:poly::poly(unsigned int a, complex *b) { order = a; std::cout << "\ntestpoint4"; complex *test; test = new complex[order+1]; std::cout << "\ntestpoint5"; delete[] test; coef = new complex[a + 1]; for (int i = order; i >= 0; i--) { coef[i] = b[i]; } }
I have been pulling my hair out for 3 days, any help is greatly appreciated.
Thanks in advance,
Carl



LinkBack URL
About LinkBacks


