Re: static function, not a member?
From: JKop (NULL_at_NULL.NULL)
Date: 06/21/04
- Next message: Andre Kostur: "Re: Position of test values in conditional expressions"
- Previous message: John Carson: "Re: static function, not a member?"
- In reply to: Howard: "static function, not a member?"
- Next in thread: Jack Klein: "Re: static function, not a member?"
- Reply: Jack Klein: "Re: static function, not a member?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Jun 2004 15:29:03 GMT
Howard posted:
> Hi,
>
> I came across some sample code for using a third-party API, and the
> code
> in it had several free-standing (i.e., non-member) functions, but
> strangely, these were declared as 'static'. My compiler tells me that
> the function has no prototype, which is weird, because there *is* a
> prototype in the header file. I was not able to find in my books any
> reference to a static function that was not a member function. The
> closest info I could find (via google) was something about making the
> symbol "local", and a suggestion that this was deprecated in C++.
>
> Can someone tell me what it means to have the static keywoard in
> front
> of a non-member function, and whether it can be safely removed for my
> use?
>
> Thanks,
> Howard
EXAMPLE 1
void Horse(void)
{
static int j = 7;
j +=2 ;
}
int main(void)
{
Horse();
Horse();
Horse();
Horse();
Horse();
// The variable j is global, but can only be accessed from
// within the Horse function. Right now, it's value is 17.
}
EXAMPLE 2
static int hello = 45;
int main(void)
{
;
}
The global variable hello cannot be accessed from outside the current CPP
file.
- Next message: Andre Kostur: "Re: Position of test values in conditional expressions"
- Previous message: John Carson: "Re: static function, not a member?"
- In reply to: Howard: "static function, not a member?"
- Next in thread: Jack Klein: "Re: static function, not a member?"
- Reply: Jack Klein: "Re: static function, not a member?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|