title: C++ extern linking
body: <p>I wanted to experiment with external linking and incomplete type declarations and wrote this example:</p>
  
  <p>Source.cpp:</p>
  
  <pre><code>//Source.cpp
  class A {
  public: 
     int a=10;
  };
  
  A* var1 = new A();
  
  void printA(A* arg)
  {
      cout &lt;&lt; arg-&gt;a &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Source1.cpp:</p>
  
  <pre><code>//Source1.cpp
  class A
  {
  public:
      int b = 20;
      int c = 30;
  };
  
  A* var2 = new A();
  
  void printB(A* a)
  {
      std::cout &lt;&lt; a-&gt;b;
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>//main.cpp   
  class A;
  extern A* var1;
  extern A* var2;
  int main()
  {
      void printA(A*);
      void printB(A*);
      printA(var1); //Prints 10
      printA(var2); //Prints 10
      printB(var2); //Prints 10
      return 0;
  }
  </code></pre>
  
  <p>After the first call of <code>printA()</code> "10" is printed just as I expected. But why "10" is also printed after the second call of <code>printA()</code> and <code>printB()</code>?</p>