C++: Trying to import class as a class member into another class, does not copy properly
<p>Thanks to all that responded to my previous thread.  There is still a problem with this simple program that I would like to solve.  I am trying to import one class into another as a member object.  The output of this program is confusing, though.  As a test of the code, I output the scalar contained within the first class object.  This works.  Then I output the scalar the is contained in the object contained as a member of the second class, and this outputs zero.  I assume that something is wrong.  Could someone shed some light on this problem?  Thanks!</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

typedef double* doublevec;

// This first class contains a vector and a scalar representing the size of the vector.
typedef class Structure1
{
 int N;
 doublevec vec;
public: 
 // Constructor and copy constructor.
 Structure1(int Nin);
 Structure1(const Structure1&amp; structurein);
 // Accessor functions:
 int get_N() { return N; }
 doublevec get_vec() { return vec; }
 // Destructor:
 ~Structure1() { delete []vec; }
} Structure1;

Structure1::Structure1(int Nin)
{
 N = Nin;
 vec = new double [N];
 for (int i = 0; i &lt; N; i++)
  {
   vec[i] = i;
  };
}

Structure1::Structure1(const Structure1&amp; structurein)
{
 vec = new double[structurein.N];
 for(int i = 0; i &lt; structurein.N; i++)
 {
  vec[i] = structurein.vec[i];
 };
}

// This class just contains the first structure.
typedef class Structure2
 {
  Structure1 structure;
 public:  
  // Constructor:
  Structure2(const Structure1&amp; structurein) : structure(structurein) {}
  // Accessor Function:
  Structure1 get_structure() { return structure; }
  // Destructor:
  ~Structure2() {}
 } Structure2;

int main (int argc, char * const argv[])
{
 const int N = 100;
 Structure1 structure1(N);
 Structure2 structure2(structure1);

 cout &lt;&lt; structure1.get_N() &lt;&lt; endl;
 cout &lt;&lt; structure2.get_structure().get_N();

 return 0;
}
</code></pre>
