title: C++ pointer wrong value
body: <p>Relatively new to C++, I'm trying to learn using dynamic memory. In this case I'm using it to store member variables.</p>
  
  <p><code>Quanternion.h</code> -</p>
  
  <pre><code>#ifndef QUATERNION_H_
  #define QUATERNION_H_
  
  class Quaternion
  {
  private:
  
  double* x = new double();
  double* y = new double();
  double* z = new double();
  double* w = new double();
  
  public:
  
  Quaternion(double x, double y, double z, double w);
  
  Quaternion(const Quaternion&amp; q);
  
  Quaternion&amp; operator=(const Quaternion&amp; q);
  
  ~Quaternion();
  
  void setQ(double *_x, double *_y, double *_z, double *_w);
  
  double * getX() { return x; }
  double * getY() { return y; }
  double * getz() { return z; }
  double * getw() { return w; }
  };
  #endif
  </code></pre>
  
  <p><code>Quanternion.cpp</code> -</p>
  
  <pre><code>#include "Quaternion.h"
  
  Quaternion::Quaternion(double x, double y, double z, double w)
  {
      double*a = &amp;x;
      double*b = &amp;y;
      double*c = &amp;z;
      double*d = &amp;w;
  
      setQ(a,b,c,d);
  }
  
  Quaternion::Quaternion(const Quaternion &amp; q)
  {
      this-&gt;x = q.x;
      this-&gt;y = q.y;
      this-&gt;z = q.z;
      this-&gt;w = q.w;
  }
  
  Quaternion &amp; Quaternion::operator=(const Quaternion &amp; q)
  {
      if (this == &amp;q)
      {
          return *this;
      }
  
      this-&gt;x = q.x;
      this-&gt;y = q.y;
      this-&gt;z = q.z;
      this-&gt;w = q.w;
  
      return *this;
  }
  
  Quaternion::~Quaternion()
  {
  }
  
  void Quaternion::setQ(double *_x, double *_y, double *_z, double *_w)
  {
      this-&gt;x = _x;
      this-&gt;y = _y;
      this-&gt;z = _z;
      this-&gt;w = _w;
  }
  </code></pre>
  
  <p>When I create a Quaternion object and set the fields, and try and print one of the variables such as X by deallocating a pointer. I do not get the result I am expecting. </p>
  
  <pre><code>int main()
  {
  
  Quaternion q1(4, 9, 2, 5);
  
  double*d = q1.getX();
  
  cout &lt;&lt; d &lt;&lt; endl;
  cout &lt;&lt; *d &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Example output -</p>
  
  <pre><code>00B1FB5C
  6.26381e+148
  </code></pre>
  
  <p>Where am I going wrong?</p>