Interview problem

describe the different between using staticand const for a function in a given class.
my answer is if one uses static, he can't use the pointer *this, and static can be used without in a given class.
Last edited on
Not quite. You see, using constant in a program- anywhere in a program- declares a value for that variable that cannot be manipulated anywhere in the program whatsoever. Static, however, works differently- it is a variable inside of a class that remains the same throughout every object of that class. So, say you have two objects, object a and object b. They are both of class foo. They both have the variable j, which is static. If I were to change the value of j in object b, it would change the value of j in object a as well. As you can see, it remains static throughout the number of objects, which can come in handy when dealing with arrays of objects of classes, where each object is of the same class.
Topic archived. No new replies allowed.