You seem to forget that indexing of arrays, allocated like arrays or from the heap with new
, are indexed from zero to size minus one.
In the PascalsTriangle
constructor you have a loop from one n
(inclusive) but the index of triangle
is from zero to n - 1
.
You have the same misunderstanding in a loop in PascalsTriangle::coeff
as well.
By having aloop from 1
to n
(inclusive) you overwrite the allocated memory, and writing beyond allocated memory leads to undefined behavior. In this case it seems that you have a memory allocator which checks for overwrites like these, and adds a special value beyond the memory you allocate. If that value is not correct when calling delete
(which calls free
) you will get a runtime error.