Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i cant figure out...what's wrong in this code:

		static void Main(string[] args)
	{
		YYY t = new YYY();
		t.I =10;
		YYY f = new YYY();
	    f.I =50;
		YYY c;
		c=t+f;
	
	}
}

public class YYY
{
	public int I
	{
		get { return i; }
		set {i=value; }
	}
	private int i;
	public static YYY operator+(YYY a,YYY b)
	{
	   YYY z = new YYY(a.I + a.I);
          return z;
	}
}

 

it gives the following Error:"No overload for method 'YYY' takes '1' arguments"

 

:confused: :confused: :o

  • *Experts*
Posted

I think you need to overload = for that to work, because of the line "c=t+f". You should have had a warning, I believe...

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

YYY z = new YYY(a.I + a.I);

YYY doesn't have a constructor that takes an integer.

 

you will need to add the following

public YYY()
{
}

public YYY(int value)
{
        i = value;
}

Posted
YYY z = new YYY(a.I + a.I);

YYY doesn't have a constructor that takes an integer.

 

you will need to add the following

public YYY()
{
}

public YYY(int value)
{
        i = value;
}

ohh now i see!!! i forgot the constructor......thanks for the help! ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...