A
Alfonso Morra
Hi,
I have a function declared thus:
int foo( int, int );
In the definition, I want to have a variable that is expensive to
create. I want to be able to save the state of this variable accross
calls - so I declare the var as a static - nothing new here.
My func defintion now looks something like this:
int foo(int a, int b) {
static Barney* = expensive_function()
....
}
My question are:
1). Is the expensive function called every, time my function is called
(I can hear a deafening YES to the question - but I'll still ask anyways)
2). Is there a way that I can have this expensive function called once
and ONLY once - the first time the function foo is called.
I thought of using bool flags, but its not clar what value they'll be
initialized at (true,false), the first time the function foo is called,
and if I asign an initialization value to a flag, the value will be
initialized to a specific pt, everytime the function is entered, the
flags will get reset - hardly the behaviour I want.
Look forward to an interesting solution. tkx
I have a function declared thus:
int foo( int, int );
In the definition, I want to have a variable that is expensive to
create. I want to be able to save the state of this variable accross
calls - so I declare the var as a static - nothing new here.
My func defintion now looks something like this:
int foo(int a, int b) {
static Barney* = expensive_function()
....
}
My question are:
1). Is the expensive function called every, time my function is called
(I can hear a deafening YES to the question - but I'll still ask anyways)
2). Is there a way that I can have this expensive function called once
and ONLY once - the first time the function foo is called.
I thought of using bool flags, but its not clar what value they'll be
initialized at (true,false), the first time the function foo is called,
and if I asign an initialization value to a flag, the value will be
initialized to a specific pt, everytime the function is entered, the
flags will get reset - hardly the behaviour I want.
Look forward to an interesting solution. tkx