我熟悉 C++,目前正在尝试学习一点 C#。话虽如此,我有 4 行代码。
[DllImport(@"Graphics.dll")]
public static extern vec2 operator * (vec2 a);
[DllImport(@"Graphics.dll")]
public static extern vec2 operator / (vec2 a);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator * (vec3 a);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator / (vec3 a);
在 VCS Express 中,他们给了我Overloadable unary operator expected
带有下划线*
的错误。/
根据MSDN ,两者都是可重载的。尽管这两个运算符都列在二元下,而不是一元下。这是怎么回事?
只是为了完整起见,这里是整个类,就像我要包装的 DLL 一样:
class GraphicsDLL
{
public struct vec2
{
float x, y;
[DllImport(@"Graphics.dll")]
vec2();
[DllImport(@"Graphics.dll")]
vec2(float ax, float ay);
[DllImport(@"Graphics.dll")]
public static extern vec2 operator + (vec2 a);
[DllImport(@"Graphics.dll")]
public static extern vec2 operator - (vec2 a);
[DllImport(@"Graphics.dll")]
public static extern vec2 operator * (vec2 a);
[DllImport(@"Graphics.dll")]
public static extern vec2 operator / (vec2 a);
};
public struct vec3
{
float x, y, z;
[DllImport(@"Graphics.dll")]
vec3();
[DllImport(@"Graphics.dll")]
vec3(float ax, float ay, float az);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator + (vec3 a);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator - (vec3 a);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator * (vec3 a);
[DllImport(@"Graphics.dll")]
public static extern vec3 operator / (vec3 a);
};
};