title: C++ can't modify private variable with setter in a class of class
body: <p>I know that setter functions are basic in C++, but I can't seem to create one properly.</p>
  
  <p>I have a class, <code>Graph</code>, that contains another class, <code>Vertex</code>.
  In <code>main</code>, I instantiate an object of type <code>Graph</code> and use that object to read a file that adds objects of type <code>Vertex</code> to the <code>Graph</code>.</p>
  
  <p>The problem is that, afterwards when I attempt to print out my <code>Graph</code> object, everything appears to be empty. I think I'm misusing pointers or references. </p>
  
  <p>Could you explain my why I have 6 <code>Vertex</code> objects, but they're all empty? (I tried to change my <code>vector</code> of <code>Vertex</code> to <code>vector*</code> but that didn't solve my problem, I think I lost the <code>Vertex</code> objects anyway...)?</p>
  
  <p><strong>Main.cpp</strong> </p>
  
  <pre><code>int main(int argc, char *argv[]){
      Graph g = Graph();
      g.readDotFile("graph.dot");
      std::cout &lt;&lt; g &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p><strong>Graph.hpp</strong></p>
  
  <pre><code>class Graph{
  
  private:
      class Vertex{
  
      public:
          Vertex();
          Vertex(std::string name);
          Vertex(Vertex const&amp; v);
          ~Vertex();
          const std::string&amp; getIdVertex()const;
          friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, Vertex const&amp; v);
          void printVertex(std::ostream &amp;os)const;
          void setStartToStart(const std::string&amp; name);
  
      private:
          std::string idVertex;
          std::vector&lt;std::string&gt; startToStart;
  
      };
  
  public:
      Graph();
      void readDotFile(std::string dotFile); // Graph from a dot file
      Graph(Graph const&amp; g);
      ~Graph();
      void addVertex(Vertex&amp; v);
      void addEdge(int typeOfEdge, std::string name1, std::string name2);
      const std::vector&lt;Graph::Vertex&gt;&amp; getVertices()const;
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, Graph const&amp; g);
      friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, Vertex const&amp; v);
      void printGraph(std::ostream &amp;os)const;
  private:
      std::vector&lt;Vertex&gt; vertices;
  };
  </code></pre>
  
  <p><strong>Graph.cpp</strong></p>
  
  <pre><code>#include "graph.hpp"  
  
  Graph::Vertex::Vertex(){}
  Graph::Vertex::Vertex(std::string name){
      idVertex = name;
  
  }
  Graph::Vertex::Vertex(Graph::Vertex const&amp; v){}
  Graph::Vertex::~Vertex(){}
  
  const std::string&amp; Graph::Vertex::getIdVertex()const{ return idVertex; }
  
  
  void Graph::Vertex::setStartToStart(const std::string&amp; v){
      startToStart.push_back(v);
  }
  Graph::Graph(){} 
  Graph::Graph(Graph const&amp; g){}   
  Graph::~Graph(){}
  const std::vector&lt;Graph::Vertex&gt;&amp; Graph::getVertices()const{ return vertices; }
  
  void Graph::readDotFile(std::string file){
      std::ifstream dotFileIn(file.c_str());
  
      std::string line;
      while (getline(dotFileIn, line)){
              // Read the file, the problem don't come from here, I just don't show the code
          addEdge(1, "origin", "destination");
          }
      }
  }
  
  void Graph::addVertex(Graph::Vertex&amp; v){ // Before create, verify the vertex does not exist
      vertices.push_back(v);    
  }
  
  void Graph::addEdge(int typeOfEdge, std::string name1, std::string name2){
      Graph::Vertex v1 = Graph::Vertex(name1);
      addVertex(v1);
      Graph::Vertex v2 = Graph::Vertex(name2);
      addVertex(v2);
      v1.setStartToStart(name2);
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, Graph const&amp; g)
  {
      g.printGraph(os);
      return os;
  }
  
  void Graph::printGraph(std::ostream &amp;os)const{
      for (unsigned int i = 0; i &lt; vertices.size(); ++i){
          vertices[i].printVertex(os);
      }
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, Graph::Vertex const&amp; v)
  {
      v.printVertex(os);
      return os;
  }
  
  void Graph::Vertex::printVertex(std::ostream &amp;os)const{
      os &lt;&lt; " vertex : " &lt;&lt; idVertex &lt;&lt; "\t";
      for (unsigned int i = 0; i &lt; startToStart.size(); ++i){
          os &lt;&lt; "startToStart: " &lt;&lt; startToStart[i] &lt;&lt; "\t";
      }
  }
  </code></pre>
  
  <p>}</p>