I just came across code that had protected static class functions, as in:
class C {
...
protected:
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.