المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Static function variable problem



C++ Programming
06-15-2009, 10:42 PM
Hello,
I have a function that is called from a dll and contains static variable:

void myFn(double data)
{
static double x;
...
}
At each iteration x increases on some value.
The problem occurs when pass diffent data at the same time (i.e. call the function more than once at the same time), x variable mixes all values.


data1[] = 1,2,3
data2[] = 4,5,6

The result for the first call must be 1+2+3 = 6
The result for the second call must be 4+5+6 = 15

But now the result for the first call will be 1+4+2+5+... and so on.

How to avoid this problem?