> The keyword "static" is used for two purposes in C++.
> 1. in class declarations to declare class methods/
> attributes.
> 2. in implementation files to prevent the
> name of a
> function/variable/constant from polluting the global
> namespace.
And here we have at least two keywords that have different usage
restrictions in different contexts. I haven't seen any C++ compilers that
would accept 'static' to limit method visibility in the same way C uses it
for functions and variables. Maybe there is one, i gave up searching. So,
even for privately used methods you still have to export their names to the
linker and just hope that compiler catches all these calls and gives you an
error. I agree that in header (class declaration) static would mean 'no this
pointer, no access to the non-static data, or whatever', but when you define
some method (that is just an ordinary function with hidden this pointer
parameter and some restrictions on who can use it) then you can't use
'static' just because it would require too much changes to the compiler code?
Don't think so, there should be better reason to make this less logical.
Another keyword is 'virtual'. For method it means 'function is accessed
using a pointer in virtual method table'. Single pointer to single piece of
code that has usually different value for each class but all instances of the
same class share the same pointer value. But for some reason there is nothing
like 'virtual member', that would be static member of the class that is
accessed using pointer that is too stored in the VMT. How many times you had
to declare something like 'virtual int class::typeid(void) { return
some_constant_value; }' for that purpose? And why is there an artifical
limitation so you can't do things the way they could be done in the
consistent way? Maybe RTTI can provide some of this functionality, never
tried (it's ugly)...
---
---------------
* Origin: A point in the middle of nowhere (2:490/31.3100)
|