
Originally Posted by
franco.amato
I still didn't understand why the static gave that behaviour if I update at every call the member variablke
Here is a small example:
void foo() {
static int counter = 0;
cout << "foo has been called " << ++counter << " times\n";
}
int main() {
for( int i = 0; i < 10; ++i ) foo();
}
void foo() {
static int counter = 0;
cout << "foo has been called " << ++counter << " times\n";
}
int main() {
for( int i = 0; i < 10; ++i ) foo();
}
To copy to clipboard, switch view to plain text mode
it will display:
foo has been called 1 times
foo has been called 2 times
foo has been called 3 times
...
foo has been called 10 times
So, as it can be easily noticed, this line:
static int counter = 0;
static int counter = 0;
To copy to clipboard, switch view to plain text mode
is called ONCE, when this line is rached for the first time. So counter variable is created once and 0 is assigned to it once. Then it remains in memory for every foo() call until the end of app execution.
So in your code point[3] was created and initialized once on the first call of paintEvent() and remained there forever (until program ends).
Bookmarks