title: vector<class> with private constructor
body: <p>I have the following situation: a class NoEntry contains data which can be inspected by the outside world, but the outside world is not allowed, in any way, to create those objects. Such a class looks like this:</p>
  <pre><code>#ifndef INCLUDED_NOENTRY_
  #define INCLUDED_NOENTRY_
  
  #include &lt;string&gt;
  
  class NoEntry
  {
      std::string d_name;
      size_t d_area = 0;
      size_t d_date = 0;
  
      public:
          std::string const &amp;name() const;
          size_t area() const;
          size_t date() const;
  
      private:
          NoEntry(NoEntry const &amp;other) = default;
          NoEntry() = default;
          NoEntry(std::string const &amp;name, size_t area, size_t date);
  };
  
  #endif
  </code></pre>
  <p>Using NoEntry objects is a privilege of certain classes, declared as friends of NoEntry. So the class contains friend declarations:</p>
  <pre><code>#ifndef INCLUDED_NOENTRY_
  #define INCLUDED_NOENTRY_
  
  #include &lt;string&gt;
  
  class NoEntry
  {
      friend class PrivilegedOne;
      friend class PrivilegedTwo;
  
      std::string d_name;
      size_t d_area = 0;
      size_t d_date = 0;
  
      public:
          std::string const &amp;name() const;
          size_t area() const;
          size_t date() const;
  
      private:
          NoEntry(NoEntry const &amp;other) = default;
          NoEntry() = default;
          NoEntry(std::string const &amp;name, size_t area, size_t date);
  };
  
  #endif
  </code></pre>
  <p>I have designed the following PrivilegedOne interface:</p>
  <pre><code>#ifndef INCLUDED_PRIVILEGEDONE_
  #define INCLUDED_PRIVILEGEDONE_
  
  #include &lt;iosfwd&gt;
  #include &lt;vector&gt;
  
  #include &quot;../noentry/noentry.h&quot;
  
  class PrivilegedOne
  {
      std::vector&lt;NoEntry&gt; d_noEntry;
  
      public:
          PrivilegedOne(std::string const &amp;fname);
  
      private:
          NoEntry nextEntry(std::istream &amp;in);    // empty name: all were read
  };
  
  #endif
  </code></pre>
  <p>Its member nextEntry is a simple one: it reads the data from file, and returns a NoEntry object.</p>
  <pre><code>//#define XERR
  #include &quot;privilegedone.ih&quot;
  
  NoEntry PrivilegedOne::nextEntry(istream &amp;in)
  {
      NoEntry ret;
  
      in &gt;&gt; ret.d_name &gt;&gt; ret.d_area &gt;&gt; ret.d_date;
  
      if (not in)                         // no more NoEntries: ensure
          ret.d_name.clear();             // that d_name is empty
  
      return ret;
  }
  </code></pre>
  <p>PrvilegedOne's constructor must read all the NoEntry objects and must store them in d_noEntry. Here is its original implementation:</p>
  <pre><code>//#define XERR
  #include &quot;privilegedone.ih&quot;
  
  PrivilegedOne::PrivilegedOne(string const &amp;fname)
  {
      ifstream in{ fname };
  
      while (true)
      {
          NoEntry next = nextEntry(in); 
  
          if (next.name().empty())
              break;
  
          d_noEntry.push_back(next);          // Not working
      }
  }
  </code></pre>
  <p>The &quot;Not working&quot; comment is the line that is causing all the problems.</p>
  <p>Why doesn't the statement do its job?
  Without modifying anything in the class NoEntry, but merely concentrating on PrivilegedOne: what must be done to allow objects of this class to store NoEntry objects in its d_noEntry vector?</p>
  <p>I think I should redesign the definition of d_noEntry. And then I'll only have to modify the line with the &quot;not working&quot; comment.</p>
  <p>But I am not sure how.</p>