我有问题。我正在尝试创建一个 dll,当我发送 2 组不同的值时,它可以计算 2 点之间的距离。但是,当我发送我的第二组值时,我意识到我的第一组值在数组中丢失了(数组用于存储值)
下面是我的代码:
int click = 0; //click is used to measure the number of times i have clicked, ie to say the number of times im injecting new (a,b) points into the function below.
double MeasureDistance(double a, double b)
{
/******* Create Array to Store The Points ********/
/** Initializing the array **/
double xDistance =0;
double yDistance =0;
double TDistance = 0;
static double **Array;
int column = 0; //used to toggle the column number
int width = 100;
int height = 100;
Array = new double *[width];
for (int i=0; i <width; i++)
{
Array [i] = new double [height];
}
/*** Now a and b are stored inside the Array[0][0] ***/
for (column =0; column <2; column ++)
{
if ((column % 2)==0)
{
Array [click][column] = a; //storing at [0,0]
}
else
{
Array [click][column] = b; //storing at [0,1]
}
}
for (int row = 2; row < click; row ++)
{
for (column = 0; column <2; column ++)
{
if ((column % 2) == 0)
{
xDistance = Array [0][column] - Array [row][column];
}
else
{
yDistance = Array [0][column] - Array [row][column];
}
}
TDistance = sqrt((xDistance * xDistance) + (yDistance * yDistance));
}
/*** Clearing up of array ***/
for (int i = 0; i < width; i++)
{
delete[] Array[i];
}
delete[] Array;
click++;
return TDistance ;
}
我意识到当我注入我的第二组 a 和 b 值时,我在数组 [0][0] 和 [0][1] 中的值丢失了,但我的第二组值存储在 [1][0]和 [1][1]。知道如何在不丢失以前值的情况下运行此脚本吗?提前感谢负载。编辑代码以清除一些查询。