Feb 12, 2016 02:38 PM
(This post was last modified: Feb 12, 2016 02:43 PM by z1995z.)
Im bit confused writing title. If Im wrong then please correct me.
What I want to do is to convert this peace of code to C#
Its from simple vector2d class. Im making same Vector2D class in C# so I want these functions/methods and I want it to work the same way as it worked in C++.
Seems that I can do - and + operators
Something like this:
But I cant do * operator. It says "Overloadable unary operator expected".
I get this error here:
I have simple multiply methods but it makes my code unreadable so Im trying to convert and use these methods from c++.
What I want to do is to convert this peace of code to C#
Code
vector2d vector2d::operator*( double num )
{
vector2d v;
v.x = num * x;
v.y = num * y;
return v;
}
double vector2d::operator*( vector2d vec )
{
return vec .x*x+vec.y*y;
}
vector2d vector2d::operator+(vector2d vec )
{
vector2d ans;
ans.x = x + vec.x;
ans.y = y + vec.y;
return ans;
}
vector2d vector2d::operator-(vector2d vec )
{
vector2d ans;
ans.x = x - vec.x;
ans.y = y - vec.y;
return ans;
}
vector2d vector2d::operator-(double num)
{
vector2d ans;
ans.x = x - num;
ans.y = y - num;
return ans;
}Its from simple vector2d class. Im making same Vector2D class in C# so I want these functions/methods and I want it to work the same way as it worked in C++.
Seems that I can do - and + operators
Something like this:
Code
Vector2D operator -(Vector2D vec)
{
Vector2D ans = null ;
ans.x = x - vec.x;
ans.y = y - vec.y;
return ans;
}But I cant do * operator. It says "Overloadable unary operator expected".
I get this error here:
Code
public double operator *( Vector2D w )
{
return w.x*x+w.y*y;
}I have simple multiply methods but it makes my code unreadable so Im trying to convert and use these methods from c++.


