[Home] [Groups] - Message: [Prev in Group] [Next in Group]
8674: [MUD-Dev] Re: PDMud thread summary
[Full Header] [Plain Text]
From: Adam Wiggins <adam@angel.com>
Newsgroups: nu.kanga.list.mud-dev
Date: Mon, 26 Oct 1998 15:24:40 -0800 (PST)
References: [1]
Organization: Kanga.Nu
On Mon, 26 Oct 1998, Jo Dillon wrote:
> Nope. Constant variables would be an oxymoron ;) A static variable
> is simply a variable whose value is shared between instances of a class
> (in C++ speak anyway). It's like a global variable but it's in the class's
> scope, which helps with name hiding.
It's slightly more complicated than that, due to C++ being a hack on top
of C. 'static' is best thought of as a way to use global variables with
a limited scope. For example:
class Foo
{
public:
static int MyStatic;
};
int Foo::MyStatic = 1;
static int MyStatic = 2;
void bar()
{
static int MyStatic = 3;
printf("MyStatic = %d\n", MyStatic);
{
static int MyStatic = 4;
printf("MyStatic = %d\n", MyStatic);
}
}
main()
{
printf("Foo::MyStatic = %d\n", Foo::MyStatic);
printf("MyStatic = %d\n", MyStatic);
bar();
}
The output will be:
Foo::MyStatic = 1
MyStatic = 2
MyStatic = 3
MyStatic = 4