Static?

Started by
10 comments, last by LessThanJoe 20 years, 6 months ago
quote:Original post by Mage2k
quote:Original post by Tibre
The short answer is like this. When you declare a method as static, you''re saying that there doesn''t have to be an instance of that object in order to call that method. Therefore, it can''t access any non-static variables or call any non-static functions. This is because the compiler has know way of knowing whether or not those non-static functions access non-static variables themselves. The only way it can know for certain that the function you are calling is doesn''t access any non-static variables, is if it is static too.
Ummm... not quite. I think a better way to word it is that you can only call non-static methods with a valid reference to an object that has been created with new. Static methods are class operations and non-static methods are object operations.
...
peace and (trance) out

Mage

Ok... yeah, I agree. That is a better way to word it. I guess what I should''ve said was ''If you are in a static method, the only variables and methods you can access are: other static methods and static members of the class you belong to, or ANY public method or variable of a specific object''.

I guess sometimes the short answer isn''t adequate. ;P
Advertisement
When it comes to helping someone understand something it never is.

This topic is closed to new replies.

Advertisement