MUD-Dev
mailing list archive
[ Other Periods
| Other mailing lists
| Search
]
Date:
[ Previous
| Next
]
Thread:
[ Previous
| Next
]
Index:
[ Author
| Date
| Thread
]
[MUD-Dev] Re: PDMud thread summary
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
- Thread context:
- [MUD-Dev] Re: PDMud thread summary, (continued)
[ Other Periods
| Other mailing lists
| Search
]