title: Shared instance with dictionary (c++)
body: <p>I'm C++ newbie here. I'm trying to implement something. My goal is simple:</p>
  
  <ol>
  <li>A shared instance which can be easily accessed in different scopes.</li>
  <li>This shared instance has a dictionary instance variable (map) to store key-value pair data. </li>
  <li>We can add a new key-value pair or get the value for a key via the public accessor.</li>
  </ol>
  
  <p>Here is my header:</p>
  
  <pre><code>// .h
  using namespace std;
  
  class Person;
  typedef map&lt;string, Person&gt; DictForPeople;
  
  class Company {
      Company();
      void setValueForKey(string key, Person value);
      Person valueForKey(string key);
  private:
      DictForPeople _dictForPeople;
  };
  
  class Person {
  public:
      Person();
      void setName(string name);
      string name();
  private:
      string _name;  // !!!: raise error here
  };
  </code></pre>
  
  <p>and the implementation (.cpp):</p>
  
  <pre><code>// .cpp
  Company::Company(){
  
  }
  void Company::setValueForKey(string key, Person value){
      _dictForPeople[key] = value;
  }
  Person Company::valueForKey(string key){
      return _dictForPeople[key];
  }
  Person::Person(){
  
  }
  void Person::setName(string name){
      _name = name;
  }
  string Person::name(){
      return _name;
  }
  </code></pre>
  
  <p>I'm trying to use <a href="https://stackoverflow.com/questions/1008019/c-singleton-design-pattern"><strong>singleton pattern</strong></a>, but it raises a lot of compilation errors. How to correctly declare a shared instance with accessors for string/map?</p>
  
  <hr>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>The above code raises an error: <strong><em>Implicit instantiation of undefined template 'std::__1::basic_string, std::__1::allocator >'</em></strong></p>
  
  <p>The environment is <strong>Xcode 6</strong>/<strong>Mac OS X 10.10</strong> with LLVM/Clang. I'm trying using C++ instead of Objective-C for some reasons.</p>
  
  <hr>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>My implementation with Singleton Pattern is the following (<a href="https://stackoverflow.com/questions/1008019/c-singleton-design-pattern">reference</a>):</p>
  
  <pre><code>// .h
  using namespace std;
  
  class Person;
  typedef map&lt;string, Person&gt; DictForPeople;
  
  class Company {
      static Company&amp; getInstance() {  // For Singleton Pattern
          static Company instance;
          return instance;
      }
  
      void setValueForKey(string key, Person value);
      Person valueForKey(string key);
  private:
      Company() {};  // For Singleton Pattern
      Company(Company const&amp;);  // For Singleton Pattern
      void operator=(Company const&amp;);  // For Singleton Pattern
  
      DictForPeople _dictForPeople;
  };
  
  class Person {
  public:
      Person();
      void setName(string name);
      string name();
  private:
      string _name;  // !!!: raise error here
  };
  </code></pre>
  
  <p>This change raises more errors:</p>
  
  <ol>
  <li><strong><em>Field has incomplete type 'Person'</em></strong>: this could be fixed by moving the class declaration <code>Person</code> above the class declaration <code>Company</code>.</li>
  <li><p>Other errors are the same message introduced before (<strong><em>Implicit instantiation of undefined template 'std::__1::basic_string, std::__1::allocator >'</em></strong>) but in different places. The C++ file <code>utility</code>  LLVM</p>
  
  <pre><code>template &lt;class _T1, class _T2&gt;
  struct _LIBCPP_TYPE_VIS_ONLY pair
  {
      typedef _T1 first_type;
      typedef _T2 second_type;
  
      _T1 first;     // &lt;&lt;&lt;-- raise the error here
      _T2 second;
  
      // pair(const pair&amp;) = default;
      // pair(pair&amp;&amp;) = default;
  
      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
  </code></pre></li>
  </ol>
  
  <hr>
  
  <p><strong>Update 3:</strong></p>
  
  <p>I forgot to mention that the above code is embedded in <code>extern "C" {...}</code> block.</p>