title: How can I copy a pointer to another class within a class to another pointer in C++?
body: <p>In other words, how can I take a pointer of a class-type that is within a different class and copy it to another pointer of the same class-type.</p>
  
  <p><strong>Here's an example:</strong></p>
  
  <pre><code>class Bananas
  {
      private:
          int peel;
          string color;
  };
  
  class Apples
  {
      private:
          Bananas *ptr1;
          Bananas *ptr2;
  
      public:
          void copyPointers();
  };
  </code></pre>
  
  <p>In the above example, I need to copy the values of <strong>ptr1</strong> to <strong>ptr2</strong>.</p>
  
  <p>Note: <strong>ptr2</strong> is empty.</p>
  
  <p><strong>Failed Attempt #1:</strong></p>
  
  <pre><code>memcpy(ptr2, ptr1, strlen(ptr1)+1);
  </code></pre>
  
  <p><strong>Failed Attempt #2:</strong></p>
  
  <pre><code>ptr2 = ptr1;
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>To further explain my function:</p>
  
  <pre><code>void Apples::copyPointers()
  {
      ptr2 = ptr1;
  }
  </code></pre>