here is a simple example of my code
class base
{
protected:
int value;
public:
base();
base(const int);
base(const base &);
~base();
];
class derived:public base
{
protected:
derived * next; // a pointer to the same datatype.
public:
derived();
derived(const int);
derived(const base &);
derived(const derived &);// This is the problem.
~derived();
... ...
};
My problem is how to write the copy constructor of the derived class, because there is a pointer to derived class as a data member inside the derived class. Do I need deep copy to copy this pointer "derived * next" ? How about "next -> next" or "next -> next > next"? It looks like a infinite loop.
Here is what I write so far
derived::derived(const derived & source):base(source)
{
if(next)
delete next;
next = new derived(source.next);
}