const function

we know that const function cant change object.can they change a static member of object?
i try that,and it can change it!why?

class c{
static int d;
void f() const {d=0;} //!
}
int c::d;
...
it has no error
no reply?!
why?
Because , static member means , a static memory field belong the class itself.
In constant function , you can't change the members that belong the object. Static member doesn't belong any object, it belongs class.

Sorry for my bad English.I hope , i could clearly explained it.
no reply?!
why?


Because you only waited a half hour.

We aren't sitting on these forums 24/7 constantly refreshing our browser to look for new questions. Give us time to respond.
There's no way that can compile. You're missing at least one semicolon.

Anyways:
http://msdn.microsoft.com/en-us/library/s1sb61xd(VS.80).aspx

What does this imply?

-Albatross
i read in forums that const function cant change member of objects .then why function f() in your code can change static int d and have no error?
Because of what Dufresne said.

Const functions just mean that 'this' is const. So you can't change any members of 'this'.

'd', however, is static, and is therefore not part of 'this', and therefore is not constant.

Static members are basically globals, just with a limited scope.
thank to Dufresne and others.

@Disch : sorry ,im new with forums
Topic archived. No new replies allowed.