A static function which is private to a class will lead to a compilation error as it will be inaccessible.
If put in the public section it will compile.
Now for const, a const function is meant not to modify any member variables of the object it is accessed for. But since it is static in this case, it won't have any objects associated with it, so there is no meaning of const for static member function. though it can b placed there without generating an error
#include<iostream.h>
class A
{
static int a;
//int b;
public:
static const void foo()
{
a++;
//b = 10; // this gives compilation error "member b cannot be used without an object"
}
static void func()
{
cout<<a;
}
};
int A::a=0;
void main()
{
A::foo();
A::func();
}
this prints 1 as output.
Login to rate this answer.