Do access modifiers work for static class functions?

I just came across code that had protected static class functions, as in:

class C {

        static int fun() { ... }

I got curious if static class functions could have access modifiers and what would it mean? Since they are class globals and not pre-instance.

Thanks, Boda Cydo.


Access modifiers in C++ do not work per-instance. They always work per-class. That is how it's always been. Which makes it perfectly logical to have them apply to static members as well.

It is a rather popular misconception that access protection in C++ is somehow supposed to work per-instance, which seems to be what inspired your question as well.

It still serves the same purpose: Only derived classes can call that static function.

It means protected: static functions can be accessed from other member functions of that class or from the member functions of the derived classes.

Need Your Help