the problem stats" copy instructor: initializes a copy of an IntSet given another IntSet as a parameter. The new IntSet is a copy of the IntSet parameter.

i need to copy my class using a constructor. IntSet is the class which is a class for setting up arrays as true or false and other array manipulation. i was having a little trouble figuring how to do this, but was thinking of doing something along these lines...

public IntSet(IntSet(b))
{
      IntSet(b) = new IntSet(a);
}

Edited 6 Years Ago by jigglymig1: n/a

You will need to extract the field values from the parameter object to set the fields in the new object.
More like this:

public IntSet(IntSet source)
{
    //copy source field value to this object
    this.Data = source.Data; // assumes that IntSet has a Data property
}

Which is used like this IntSet newSet = new IntSet(oldSet); in code.

If you wish to make a clone then you can also write a clone method.

public IntSet Clone()
{
    IntSet copy = new IntSet();
    // copy relevant field values here
    copy.Data = this.Data;
    return copy;
}

Which is used like this IntSet newSet = oldSet.Clone(); in code.

If you also wish to have both options then the Clone method can use the constructor to do the cloning.

public IntSet Clone()
{
    return new IntSet(this);
}

Edited 6 Years Ago by nick.crane: n/a

This question has already been answered. Start a new discussion instead.