【发布时间】:2013-01-15 23:06:54
【问题描述】:
- 我有一个 RoundedSum 对象,它主要检查产品的价格和一个整数和到数据库中。
- 我有一个 UnRoundedSum 对象,它基本上继承了 RoundedSum 并覆盖了 checkinsum 函数,并将与最接近的整数的差值检查为未计入的
- UnRoundedSum 调用 base 的 checkinsum(productid,int) 来检查 数据库中的价格值这是我的命名空间 SumRounding,它有 2 课程
namespace DatabasePricing.SumRounding
{
public class Roundedsum
{
public void checkinsum(int productid,int sum)
{
//Checks in price in the price table
//dbobject("price",productid,sum);
int temp_int = sum;
}
}
public class UnRoundedSum : Roundedsum
{
public void checkinsum(int productid,float sum)
{
//Since the sum is a float it will check the difference
//into unroundedsum table in the database
int intsum = (int)sum;
float tempfloat = sum - intsum;
//Check this remaining float into the database under unaccounted
// dbobject("unroundedsum",productid,tempfloat);
//Now call the integer checksum with the integer value
checkinsum(productid,intsum);
}
}
}
让我们假设我现在创建了一个用于测试 rite 的主要函数,因为它在我的项目中不起作用。嗯,这就像上述类的测试对象。
using DatabasePricing.SumRounding;
namespace DatabasePricing
{
class testingrounding
{
static void Main() {
int product_id = 1;
float float_value = 1.1f;
UnRoundedSum obj1 = new UnRoundedSum();
//This call produces StackOverflow Exception
obj1.checkinsum(1, float_value);
int price = 200;
//I tried with integer value to test RoundedSum object
//it is still throwing an exception
//This call also produces StackOverflow Exception
obj1.checkinsum(1, price);
}
}
}
当我尝试调试时,它总是在引发 StackOverflow 错误之前被 checkinsum() 捕获。当我尝试调试时,即使在执行后它也会返回到 checkinsum()。由于某种原因,它不断回来。我不知道会出什么问题。
【问题讨论】:
-
这很可能是递归调用
checkinsum引起的 -
在执行对 UnRoundedSum.checkinsum 的调用时,它会在什么时候停止调用自己?由于没有终止案例,因此您很快就会填充调用堆栈。顺便说一句,因为这是一个尾调用,所以相同的代码很可能会进入无限循环,而不会导致 x64 抖动上的 stackoverflow
-
方法
checkinsum是递归的。 您应该使用 Visual Studio 来帮助定位此类问题。 -
C++没有什么,所以请不要标记它是C++。
-
我想我有点困惑,因为我已经@it 很长时间了。也许你们所有人都看对了。让我更好地理解你所有的 cmets。谢谢你的帮助..
标签: c# sql exception stack-overflow