title: C++ - non-static void* member pointing to another non-static member of different objects having same address but distinct value
body: <p>This question title is not clear and a bit broken. I tried to use a <code>void*</code> which is a member to store the address of another member. I accidentally found a weird problem. There were three <code>Object</code> objects created inside a <code>vector&lt;T&gt;</code>. But when I look at the value of those three <code>val_addr</code>, they always point to the same address, but apparently each <code>val</code> is always unique.</p>
  
  <pre><code>class Object {
  
  protected:
      int val {0};
  
      void *val_addr = nullptr;
  
      std::vector&lt;Object&gt; objs;
  
  public:
      Object() = default;
  
      Object(int val) 
      {
          this-&gt;val = val;
          this-&gt;val_addr = (void *) &amp;this-&gt;val;
          std::cout &lt;&lt; "val_addr: " &lt;&lt; val_addr &lt;&lt; "\n"; // always 0X123456 for example
      }
  
      std::vector&lt;Object&gt;&amp; get_objs() 
      {
          return objs;
      }
  
  };
  
  class Iterable : public Object {
  public:
      Iterable(const std::set&lt;int&gt;&amp; values) { // {1, 2, 3} inside values
          for (const auto &amp; c : values) {
              this-&gt;objs.emplace_back(c);
          }
      };
  };
  </code></pre>