J
jasonkong1989
Question:
The below code compiles, but i am not sure how. I have a static member
variable that, when defined, calls a private constructor. I was under
the impression that the private constructor would be inaccessable to
the static member variable. Where am I mistaken?
class MyClass
{
public:
static MyClass m_myclass;
static int myfunc(){return 5;}
private:
MyClass(int x=9){int y = x; y++;} //private default constructor
};
MyClass MyClass::m_myclass(9); //m_myclass is defined, private
constructor is called
int main( )
{
int x = MyClass::m_myclass.myfunc(); //MyClass::m_myclass is
actually used
x++;
return 0;
}
The below code compiles, but i am not sure how. I have a static member
variable that, when defined, calls a private constructor. I was under
the impression that the private constructor would be inaccessable to
the static member variable. Where am I mistaken?
class MyClass
{
public:
static MyClass m_myclass;
static int myfunc(){return 5;}
private:
MyClass(int x=9){int y = x; y++;} //private default constructor
};
MyClass MyClass::m_myclass(9); //m_myclass is defined, private
constructor is called
int main( )
{
int x = MyClass::m_myclass.myfunc(); //MyClass::m_myclass is
actually used
x++;
return 0;
}