I have this question because of the singleton/named constructor. In both cases, the real constructors are protected or private, neither of which can be accessed from outside
According to the standard §11/p2 Member access control [class.access] (Emphasis Mine):
A member of a class can also access all the names to which the class has access. A local class of a member function may access the same names that the member function itself may access.113
113) Access permissions are thus transitive and cumulative to nested and local classes.
Since a static member function is a member of a class it has access to all the names to which the class has access and consequently to the constructor of the class itself.
Consequently, in your example:
class A {
A(int x);
public:
static A createA() { return A(0); } // named constructor
};
static member function A::createA()
has access to call private
constructor A::A(int)
.