- 基本的に製品の価格と整数の合計を DB にチェックする RoundedSum オブジェクトがあります。
- 基本的に RoundedSum を継承し、checkinsum 関数をオーバーライドし、最も近い整数との差を unaccounted にチェックする UnRoundedSum オブジェクトがあります。
- UnRoundedSum は base の checkinsum(productid,int) を呼び出して価格値を DB にチェックします これは 2 つのクラスを持つ私の名前空間 SumRounding です
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);
}
}
}
これは、私のプロジェクトで動作していないため、儀式をテストするために作成したメイン関数を想定しています。これは、上記のクラスのテストオブジェクトのようなものです。
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() に戻ります。なぜか戻ってきます。何がそんなにうまくいかないのかわからない。