title: What is the better way to manage class instances within a factory?
body: <p>I've got a "design" problem in a C++ project.</p>
  
  <p>I have a class, named <code>Currency</code> (which can be <code>"USD"</code>, <code>"EUR"</code>, and so on..., and got some methods)
  There are many instances of this class new-ed everywhere in the project, but there can only be a bunch of different currencies (~100).</p>
  
  <p>So I wrote a method which allocates a <code>Currency</code> the first time it's asked, and returns an existing <code>Currency</code> otherwise :</p>
  
  <pre><code>    class Currency 
      {
      public:
        typedef std::map&lt;std::string, Currency*&gt; CurrencyMap_t;
      public:
        static CurrencyMap_t _currencies;
  
      public:
        static const Currency&amp; getCcy(const std::string&amp; name)
        {
          CurrencyMap_t::const_iterator it(_currencies.find(name));
  
          if (it == _currencies.end())
            it = _currencies.insert(std::make_pair(name, new Currency(name))).first;
  
          return *(it-&gt;second);
        }
  
      private:
        // can't instantiate from outside
        Currency();
        Currency(const Currency&amp; other);
      private:
        // private ctor
        explicit Currency(const std::string&amp; name) {... }
      };
  </code></pre>
  
  <p>So, now, I only have one instance of each different <code>Currency</code>.</p>
  
  <p>But, I can't anymore have a class holding a <code>Currency</code> member, because the default-constructor is not defined :</p>
  
  <pre><code>    class CcyPair
      {
      public:
        CcyPair(const Currency&amp; ccy1, const Currency&amp; ccy2) {}
      private:
        Currency _ccy1; // won't compile because "no default-constructor available"
        Currency _ccy2;
      };
  </code></pre>
  
  <p>And I don't want to hold <code>Currency</code> pointers in <code>CcyPair</code> class.</p>
  
  <p>Do you have a better way to implement such a "pattern" which ensures that if two instances of a class (here the <code>Currency</code> class) got the same attributes, then it's in fact the <strong>same</strong> instance (same underlying reference) ?</p>