title: ":" Colon in a Struct constructor
body: <p>I have checked some topics about Bitfields in a struct constructor, but I couldn't find any explanation about this line of code:</p>
  
  <pre><code>vertex(string s) : name(s) {}
  </code></pre>
  
  <p>in this block of code:</p>
  
  <pre><code>struct vertex {
     typedef pair&lt;int, vertex*&gt; ve;
     vector&lt;ve&gt; adj; //cost of edge, destination vertex
     string name;
     vertex(string s) : name(s) {}
  };
  </code></pre>
  
  <p>The whole code structure is about implementing a weighted graph which I have seen in this Website:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct vertex {
      typedef pair&lt;int, vertex*&gt; ve;
      vector&lt;ve&gt; adj; //cost of edge, destination vertex
      string name;
      vertex(string s) : name(s) {}
  };
  
  class graph
  {
  public:
      typedef map&lt;string, vertex *&gt; vmap;
      vmap work;
      void addvertex(const string&amp;);
      void addedge(const string&amp; from, const string&amp; to, double cost);
  };
  
  void graph::addvertex(const string &amp;name)
  {
      vmap::iterator itr = work.find(name);
      if (itr == work.end())
      {
          vertex *v;
          v = new vertex(name);
          work[name] = v;
          return;
      }
      cout &lt;&lt; "\nVertex already exists!";
  }
  
  void graph::addedge(const string&amp; from, const string&amp; to, double cost)
  {
      vertex *f = (work.find(from)-&gt;second);
      vertex *t = (work.find(to)-&gt;second);
      pair&lt;int, vertex *&gt; edge = make_pair(cost, t);
      f-&gt;adj.push_back(edge);
  }
  </code></pre>
  
  <p>What does this bit do and what is the purpose? </p>
  
  <pre><code>vertex(string s) : name(s) {}
  </code></pre>