Я работаю над программой, которая считывает полином в качестве входных данных, выводит полином, оценивает его и добавляет два полинома, сохраняя при этом циклически связанный список. Анализ с использованием GDB показал, что существует проблема с функцией-членом Next() шаблона класса CircListIterator. Что я могу делать не так с Next()? Код и выходные данные воспроизведены ниже. Прошу прощения за длинный код.
main.cpp
#include
#include "Polynomial.h"
int main() {
Polynomial poly1, poly2;
Polynomial result;
std::cout > poly1;
std::cout > n; // Read number of terms
for (int i = 0; i < n; i++) {
is >> coef >> expon;
if (coef != 0) { // Ignore terms with zero coefficients
temp.Init(coef, expon);
x.poly.Attach(temp);
}
}
return is;
}
std::ostream& operatorcoef < 0) {
os coef);
if (absCoef != 1 || t->expon == 0) {
os expon != 0) {
os expon != 1) {
os coef * std::pow(x, t->expon);
t = iter.Next();
}
return result;
}
Вывод:
Enter the first polynomial (format: number_of_terms coef1 expon1 coef2 expon2 ...): Term with Exponent -1 and coefficient 0 added.
3 1 2 2 1 1 0
Term with Exponent 2 and coefficient 1 added.
Term with Exponent 1 and coefficient 2 added.
Term with Exponent 0 and coefficient 1 added.
Polynomial 1: x^2 + 2x + 1
Enter the second polynomial (format: number_of_terms coef1 expon1 coef2 expon2 ...): Term with Exponent -1 and coefficient 0 added.
3 1 2 3 1 2 0
Term with Exponent 2 and coefficient 1 added.
Term with Exponent 1 and coefficient 3 added.
Term with Exponent 0 and coefficient 2 added.
Polynomial 2: x^2 + 3x + 2
Value of Polynomial 1 at x = 2 is: 9
Value of Polynomial 2 at x = 2 is: 12
Summing: p->coef=1, q->coef=1
Term with Exponent 2 and coefficient 2 added.
Summing: p->coef=2, q->coef=3
Term with Exponent 1 and coefficient 5 added.
Summing: p->coef=1, q->coef=2
Term with Exponent 0 and coefficient 3 added.
Term with Exponent 2 and coefficient 2 added.
Term with Exponent 1 and coefficient 5 added.
Term with Exponent 0 and coefficient 3 added.
Program received signal SIGSEGV, Segmentation fault.
0x000055555555657b in CircListIterator::Next (this=0x7fffffffeb10) at /home/CircListIterator.cpp:42
Подробнее здесь: https://stackoverflow.com/questions/787 ... cular-list