我将乘以用户必须输入的两个多项式。c/C++链接列表
在第一步(正从用户信息)我得到这个错误:
Unhandled exception at 0x00a315cb in linked polinomials.exe:
0xC0000005: Access violation writing location 0x00000000.
我之后,我想进入多项式的其他元素此错误。
struct polynomial{
float coef ;
int exp ;
polynomial *next ;
} *first, *second ,*result;
first = new(polynomial);
//init first
first ->coef = 0;
first->exp = 0 ;
first->next = 0;
while(ch != 'n')
{
cin >> temp_c ;
cin >> temp_e ;
first->coef = temp_c;
first->exp = temp_e;
cout << "Do you want to enter another ? (y or n) :" << endl;
ch = getch();
first = first->next;
}
因为这是C++而不是C,为什么不使用std ::清单? – 2012-07-17 08:15:17
没有C/C++这样的东西。不要在C++中使用指针,至少在所有方面都是如此。 – 2012-07-17 08:16:54
当你的程序崩溃时,你应该做的第一件事就是在调试器中运行它。它会帮助你找到崩溃的位置,并且让你检查变量以查明原因可能是什么。 – 2012-07-17 08:28:07