Possible Duplicate:
C++ – Why static member function can’t be created with ‘const’ qualifier
Was curious to know the reason why static member functions cant be declared as const or volatile or const volatile ?
#include<iostream>
class Test
{
static void fun() const
{ // compiler error
return;
}
};
Because that’s what the standard says:
9.4.1 Static member functions [class.static.mfct]
The reason for this is that a
const(orvolatileorvirtual)staticmethod wouldn’t make sense (in the traditional sense, see below). For example,constimplies you can’t modify the object’s members, but in the case of statics, there’s no object to talk about.You could argue that a
conststaticcould apply to otherstaticmembers, but this option was regarded as pointless.