title: C++ extern keyword and global variables
body: <p>I have two files called file_utils.h and file_utils.cpp which contain some methods and variables which are used by different classes. Here's an example of how it looks:</p>
  
  <p>file_utils.h:</p>
  
  <pre><code>namespace my_namespace
  {
  extern Foo* foo;
  extern Bar* bar;
  
  void my_function(Blah* blah);
  }
  </code></pre>
  
  <p>file_utils.cpp</p>
  
  <pre><code>#include "file_utils.h"
  
  void my_namespace::my_function(Blah* blah)
  {
      foo = 0;    // undefined reference to my_namespace::foo
      bar = 0;    // undefined reference to my_namespace::bar
      //...
  }
  </code></pre>
  
  <p>some_class.cpp</p>
  
  <pre><code>#include "file_utils.h"
  
  some_function()
  {
      my_namespace::my_function(blah);
      this-&gt;foo = *my_namespace::foo; // will that work ok?
  }
  </code></pre>
  
  <p>So the errors are in the comments. If I remove the extern keyword I get <code>multiple definition of my_namespace::foo</code> error. What is the problem? Is that even a good idea from design standpoint or should I try to use a class with static members and methods instead?</p>