0

Trying to execute the code below prevents me from moving forward. In my "Theline" class I have a constructor that accepts two arguments (int) but the error message I get says "Cannot convert from 'ConsoleApplication1.Point' to 'int'" What am I missing?

public static void Main()
     {
     Point a0 = new Point(0, 0);
     Point a1 = new Point(-1, -1);
     Theline line = new Theline(a0, a1);
     }
3
  • 2
    You're missing the fact that there is no way to convert from a Point to an int. Why do you think this is legal code? What do you expect to happen? Commented Sep 12, 2015 at 20:44
  • You should change your TheLine class constructor to accept Points because to define the line you need two points. Commented Sep 12, 2015 at 20:45
  • in 2d scene point have two ints (x and y). if you want to create line from two points you have to pass in Theline two points. and there are some drawing algorithms such as Bresenham's Line Algorithm you can search for that in google. Commented Sep 12, 2015 at 20:52

3 Answers 3

3

Your Theline connstuctor accepts int and you send it a Point object...

Simply change it to

Theline line = new Theline(a0.X, a1.Y);

You can either change the Theline constructor parameters to type of Point.

Or anything else you need..

Goodluck.

Sign up to request clarification or add additional context in comments.

Comments

0

Indeed, what Slashy says.

Or since you want a line to be created, make your TheLine constructor accept 2 points instead of ints.

2 Comments

How do I do that exactly? public TheLine(int a0.X, a0.Y, a1.X, a1.Y)?
It depends on your implementation of the Theline class, can you show me the code? Your suggested answer would work if you change your constructor so it accepts 4 ints. But letting it accept 2 Points seems more logical to me.
0

If you really, really want to use the Point, then I guess you could try:

public Theline(Point pointA, Point pointB) : this (pointA.X, pointB.Y)
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.