0

I'm having a small issue calling in the Icloneable interface

I've told the class I want to use the interface as such:

class UnitClass: ICloneable

and have placed in a function for Cloning

    public Object Clone()
    {
        return this.MemberwiseClone();
    }

however for some reason the program is telling me that I have not implemented System.ICloneable.clone() I even tried giving the function the explicit name like so...

 public Object System.ICloneable.Clone()

but with little effect, anybody know what I'm doing wrong?

edit: Full class

class UnitClass: ICloneable
{

//-----------------------------------------------------------------------------------------------
//----------------------------------------------Variables----------------------------------------

    private int unitID; //added for xml
    private string unitName;
    private int unitBaseHP;
    private int unitCurrentHP;
    private Carrier unitCarrier;
    private int unitRechargeTime;
    private int turnLastPlayed;
    private int strengthAgainstFighters;
    private int strengthAgainstBombers;
    private int strengthAgainstTurrets;
    private int strengthAgainstCarriers;

//-----------------------------------------------------------------------------------------------
//---------------------------------------------Constructor---------------------------------------

    public UnitClass()
    {
            unitID = 0;
            unitName = "Name Not Set";
            unitBaseHP = 0;
            unitCurrentHP = 0;
            unitCarrier = null;//Carrier works as faction ie red/blue or left/right
            unitRechargeTime = 0;
            turnLastPlayed = 0;
            strengthAgainstFighters = 0;
            strengthAgainstBombers = 0;
            strengthAgainstTurrets = 0;
            strengthAgainstCarriers = 0;
    }

//-----------------------------------------------------------------------------------------------
//---------------------------------------------Gets and Sets-------------------------------------

    public int UnitID//public
    {
        set { unitID = value; }
        get { return unitID; }
    }

    public string UnitName//public
    {
        set { unitName = value; }
        get { return unitName; }
    }

    public int UnitBaseHP//public
    {
        set { unitBaseHP = value; }
        get { return unitBaseHP; }
    }

    public int UnitCurrentHP//public
    {
        set { unitCurrentHP = value; }
        get { return unitCurrentHP; }
    }

    public Carrier UnitCarrier//public
    {
        set { unitCarrier = value; }
        get { return unitCarrier; }
    }

    public int UnitRechargeTime//public
    {
        set { unitRechargeTime = value; }
        get { return unitRechargeTime; }
    }

    public int TurnLastPlayed//public
    {
        set { turnLastPlayed = value; }
        get { return turnLastPlayed; }
    }

    public int StrengthAgainstFighters//public
    {
        set { strengthAgainstFighters = value; }
        get { return strengthAgainstFighters; }
    }

    public int StrengthAgainstBombers//public
    {
        set { strengthAgainstBombers = value; }
        get { return strengthAgainstBombers; }
    }

    public int StrengthAgainstTurrets//public
    {
        set { strengthAgainstTurrets = value; }
        get { return strengthAgainstTurrets; }
    }

    public int StrengthAgainstCarriers//public
    {
        set { strengthAgainstCarriers = value; }
        get { return strengthAgainstCarriers; }
    }

//---------------------------------------------------------------------------

    public object Clone()
    {
        return this.MemberwiseClone();
    }
}
dingbat
  • 1
  • 1
  • 2
  • 1
    The last definition is wrong (you cannot be `public` and implement a method explicitly at the same time), but the first one should have worked. – Jon Feb 07 '13 at 15:19
  • 1
    Can you post the whole class? Or better, a minimal class wit the same problem? – Kobi Feb 07 '13 at 15:20
  • 1
    Delete the generated method and try to add it again. Right-click on Iclonable and choose `Implement Interface` > `Implement Interface`. Compile to see if it works fine. – Rui Jarimba Feb 07 '13 at 15:22
  • 1
    You wouldn't have defined your own class called object? If so, try defining your method like `public System.Object System.ICloneable.Clone()` – sgmoore Feb 07 '13 at 15:23
  • Your class compiles: http://ideone.com/aD3dc2 The error is probably elsewhere. – Kobi Feb 08 '13 at 16:05

1 Answers1

0

This built fine for me.

public class MyClone : ICloneable
{
    public object Clone()
    {
        return this.MemberwiseClone();
    }
}

You don't perhaps want to share any more of your class? Nothing is really jumping out at me.

cameronjchurch
  • 410
  • 3
  • 7