c++的,很奇怪啊~~高手帮忙看一下吧,把我全部分都贡献出来了。。。

来源:百度知道 编辑:UC知道 时间:2024/06/24 01:50:33
请高手帮忙看看吧~~怎么想都想不出哪儿出错了!
//主函数开始
int main (int argc, char* argv[])
{
{
cout << "Looking for three 'magic' items: Should print 'magic' three times" << endl;
EnhancedLinkedList<string> l;

l.push_back ("magic");//这是在链表表尾添加结点的函数,没有错
l.push_back ("one");
l.push_back ("two");
l.push_back ("three");
l.push_back ("magic");
l.push_back ("four");
l.push_back ("five");
l.push_back ("magic");

LinkedList<string> got = l.find_all("magic");//应该就是这个函数有问题吧,详细代码见后面
got.dump();//这是打印函数,没有错
cout << endl;
}//运行到这儿出的问题,有这括号的话,后面的代码都执行不了,出现abnormal program termination的问题。没有它的话,后面的代码能执行,但最后还是会出现这样的错误。可是别的程序段同样有括号,照样能运行,如下面那一段

1.标准C++ 有括号时 变量或对象的作用范围都在括号里面
如果在括号里声明了一个变量或对象,在括号外面使用该变量或对象就会出现没有声明的错误

2.只有在try块内或try块内调用的函数内throw抛出异常才会被catch捕获到
否则catch无法捕获,此时会自动调用c++的默认terminate()函数,默认情况下,该函数将会执行Abort()函数中断程序的执行

你的程序出现abnormal program termination这个错误,应该是在try块外抛出了异常
在前面加个try,try块后面用catch捕获
try
{
cout << "Looking for three 'magic' items: Should print 'magic' three times" << endl;
EnhancedLinkedList<string> l;

l.push_back ("magic");//这是在链表表尾添加结点的函数,没有错

...

}
catch(ListItemNotFoundException& e)
{

... //处理异常

}

您好 分析您的abnormal program termination可能是以下原因

1.{}中的代码部分叫做一个“块”
EnhancedLinkedList<string> l;

是在块内调用的 但是在块外又用到了就会出错
2。 引入的头文件是否正确

3.编译器可能存在问题

上下两个EnhancedLinkedList<string> l是不同的