Using static function in class where a variable depends on constructor
<p>Lets say I have a class with a static function. This function is called as static by another part of the code, without instantiating a class object. However, this static function also has in its code a dependance on variable x. x, however, is only initialized to a certain value or cleared in the constructor. But, given that no object of the class is instantiated, I believe that the variable is undefined. So, I have a few questions:</p>

<p>1) Is the constructor called at all?</p>

<p>2) Is the variable x undefined?</p>

<p>How can I work around a case like that?</p>

<p>In the example below, i'd want y to be 25, but can it ever be?</p>

<pre><code>class CExample
{
public:

    CExample(void);
    ~CExample(void);
    static void foo();

    int x;
};

CExample::CExample()
{
    x = 5;
}


void CExample::foo()
{
    int y = x*5;

}
</code></pre>
