Copy Constructor with reference variable
<p>I have a class as given below, I want to write a copy constructor for the same. 
I need to create a deep copy constructor for this. following code is printing x and c properly but value of y here is garbage.</p>

<pre><code>#include "stdafx.h"
#include &lt;string.h&gt;
class MyClass
{
public:

 MyClass(int a) : y(a) {
 }
 MyClass(const MyClass &amp;myClass) : y(myClass.y)
 {
  x = myClass.x;
  c = new char[10];
  strcpy(c, myClass.c);
 }

  int x;
  char *c;
  int &amp;y;

};

int _tmain(int argc, _TCHAR* argv[])
{
 MyClass m1(0);
 m1.c = new char[10];
 strcpy(m1.c, "gourav");
 m1.x = 10;
 m1.y = m1.x;

 MyClass m2 = m1;

 printf("x=%d\nc=%s\ny=%d\n", m2.x, m2.c, m2.y);
 return 0;
}
</code></pre>
