-1

I have a class :

`class Myclass
{
   public:
     MyClass ( void );
     AddNumber ( const int num );
     CopyCurrentObject ( void );

   private:
     int * array
     int size;
     int maxSize;
     MyClass * objetcts[10];
}

How can I create a copy of my current object and save it to MyClass * objects[10]?

With the copy I mean that I want to create a temporary object with current values of my current object ( elements in array, size, maxSize ) and store it to the MyClass * objects[10]. It's basically something like back-up.

I create the temporary object and store the object to array like this :

MyClass * temp = new MyClass ( * this ); MyClass objects[cnt++] = temp;

The problem is with int * array because this way it's pointing to my object array so whenever i add a value in my object, stored objects in MyClass * objects[10] have it too.

kvway
  • 494
  • 4
  • 16

1 Answers1

0

You should implement the copy constructor and the assignment operator.

Myclass(const Myclass& orig); Myclass& operator=(const Myclass& orig);

Epsilon_
  • 73
  • 5