What i mean by vice versa....
A static method can access non static members
A static member function cannot access non-static members using
/unqualified names/, but it can if those the names are qualified (by dot
(.), arrow (->) or :
(in the same way those members would be accessed
from code in a non-member function such as main()).
The thing to remember is that unqualified names within a member function
that resolve to non-static members of the same class act as if they were
preceded by "this->", implying that each instantiated object of the class
has its own copy of the data (or that it makes sense to call a member
function that requires a "this" object to operate upon).
A static member function has no "this" object, so it wouldn't make much
sense for code within such a function to say something like
int i = length();
meaning:
int i = this->length();
if there's no implicit object to apply the length() function to. So that
isn't allowed.
On the other side of the coin, within a /non-static/ member function, all
uses of unqualified static member names refer, by definition, to the same
object...although it makes equally little sense to /qualify/ these names
with . or -> or :: (well, the latter could make sense to force a
non-default scope resolution), C++ allows them all just so we all have
more options for creating cryptic code ;-)
-leor
Leor Zolman
BD Software
(e-mail address removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at
www.bdsoft.com/tools/stlfilt.html