c++ return怎么不起作用啊?

来源:百度知道 编辑:UC知道 时间:2024/06/05 01:48:54
void insert_sqlist(sqlist L,double x, int i)
{
if (L.last == maxsize ) cout << endl
<< "The squence list is full";
if((i < 1) || (i > L.last))
{
cout << endl
<<"Exception:index out of bounds";
return ;
}
for(int j =L.last; j >= i; j--)
{
L.data[j] = L.data[j-1];
}
L.data[i - 1] = x;
L.last = L.last + 1;
}
我在main()输入insert_sqlist(L,10.0,11);它打印了<<"Exception:index out of bounds";还继续执行下面的语句,我在java里测试了这个return,没问题啊,函数马上返回了
我用return是希望碰到索引超界就不要再执行下面的代码,可是我反复调试总是要执行.

你再试试,可能是其他地方出问题。return 是返回了。

函数类型是void的,为什么还用return呢?
用break啊。

RETURN 没道理不返回 你自己的问题吧~

return;