Why does private constructor accessible when defining/initializing static member?
Example code is as follows.
[EDIT]
//CA.h
#pragma once
class CA
{
private:
static CA m_Instance;
CA();
~CA();
};
//CA.cpp
#include "CA.h"
CA CA::m_Instance;
CA::CA()
{
}
CA::~CA()
{
}
// StaticMemberPrivateConstructor.cpp
#include <iostream>
#include "CA.h"
int main()
{
std::cout << "Hello World!\n";
}
Above code successfully compiles and runs.
I know the reason why definition of static member variable has to be placed outside of its class.
Why do non-constant static variables need to be initialized outside the class?
C++ static member variable and its initialization
How to initialize private static members in C++?
AFAIK, the example code should give error C2248.
However, the example code does not give error C2248. Why?
My assumption is "Static Member Definition" is considered as public static member function. Therefore, it has permission granted to private constructor.
Kind and elaborate answer will be sincerely appreciated.