title: Error using pointer to get value, but it is correct to return directly, why?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  //define class C
  class C {
   public:
    C() = default;
    ~C() = default;
  
    double x() { return x_; }
  
    void set_x(double x) { x_ = x; }
  
    double y() { return y_; }
  
    void set_y(double y) { y_ = y; }
  
   protected:
    double x_;
    double y_;
  };
  
  //define class B
  class B {
   public:
    B() = default;
    ~B() = default;
  
    void set_c(std::vector&lt;C&gt; c) { c_ = c; }
  
    std::vector&lt;C&gt; c() { return c_; }
  
    std::vector&lt;C&gt; *mutable_c() { return &amp;c_; }
  
   protected:
    std::vector&lt;C&gt; c_;
  };
  
  //define class A
  class A {
   public:
    A() = default;
    ~A() = default;
  
    B b() { return b_; }
  
    void set_b(B b) { b_ = b; }
  
   protected:
    B b_;
  };
  
  int main() {
    A a;
    B b;
    C c1, c2;
    std::vector&lt;C&gt; c;
    c1.set_x(11.11);
    c1.set_y(22.22);
    c.push_back(c1);
    c2.set_x(33.33);
    c2.set_y(44.44);
    c.push_back(c2);
    b.set_c(c);
    a.set_b(b);
  
   //get value
    for (auto it : *(a.b().mutable_c())) {
      std::cout &lt;&lt; &quot;111:&quot; &lt;&lt; it.x() &lt;&lt; std::endl;
      std::cout &lt;&lt; &quot;222:&quot; &lt;&lt; it.y() &lt;&lt; std::endl;
    }
  
    std::cout&lt;&lt;std::endl;
  
     //get value
      for (auto it : a.b().c()) {
      std::cout &lt;&lt; &quot;333:&quot; &lt;&lt; it.x() &lt;&lt; std::endl
      std::cout &lt;&lt; &quot;444:&quot; &lt;&lt; it.y() &lt;&lt; std::endl;
    }
    return 1;
  }
  </code></pre>
  <p>Results in the error stated in the title. I do realize that if the first way returns the wrong result, the second way is correct.
  But, here I want to understand what is the meaning of this error and why can't I use it this way.</p>
  <p>//wrong</p>
  <p>111:0</p>
  <p>//wrong</p>
  <p>222:4.64953e-310</p>
  <p>111:33.33</p>
  <p>222:44.44</p>
  <p>333:11.11</p>
  <p>444:22.22</p>
  <p>333:33.33</p>
  <p>444:44.44</p>