Global pointer to object causes access violation?
<p>Maybe you will be able to clear something for me, because I don't know exactly where my thinking is flawed. First some code:</p>

<p>Talker.h:  </p>

<pre><code>class talker       
{
    public:
    talker();
    void sayHello() {cout &lt;&lt; "Hello";} ;
};
</code></pre>

<p>anotherClass.h:</p>

<pre><code>class anotherClass
{
    public:
    anotherClass();
    void doSomethingYourself() { cout &lt;&lt; "will do"; };
    void askHimToSayHello() { pointerToTalker-&gt;sayHello; };  
                          //Access violation, bad pointer(?)
};
</code></pre>

<p>common.h:</p>

<pre><code> static talker *pointerToTalker;       
      // if I add here "= new talker", code works fine
</code></pre>

<p>main.cpp:</p>

<pre><code>#include "common.h"
int main()
{
    pointerToTalker = new talker;            // Here is the bug, but why?
    pointerToTalker -&gt; sayHello;             // says Hello alright

    anotherClass *pointerToAnotherClass = new anotherClass;
    pointerToAnotherClass -&gt; doSomething ();  //Does something OK

    pointerToAnotherClass -&gt; askHimToSayHello(); // Causes access violation 
}
</code></pre>

<p>Of course functions are a bit more complex, and each is implemeted in coresponding .cpp including "common.h". My question is - why pointerToTalker, if initialized inside main() does not work inside anotherClass::AskHimToSayHello()? It should pointing to valid memory by the time it is used there.
It is my "Hello world, OOP!" btw, so please be gentle if there is no hope for me :)</p>

<p>Sorry for the childish style btw. It helps me cut down the code I have to something more compact without me loosing the big picture :).</p>
