我在C中有以下内容
typedef void (*procfunc)(V2fT2f *, float);
typedef struct {
procfunc func;
procfunc degen;
} Filter;
const Filter filter[] = {
{ brightness },
{ contrast },
{ extrapolate, greyscale },
{ hue },
{ extrapolate, blur }, // The blur could be exaggerated by downsampling to half size
};我把它带到C#给我这个
public delegate void procfunc(ImagingDefs.V2fT2f[] quad,float t);
public class Filter
{
public procfunc func;
public procfunc degen;
};
public Filter[] filter = new Filter[]
{
new Filter { func = brightness },
new Filter { func = contrast },
new Filter { func = extrapolate, degen = greyscale },
new Filter { func = hue },
new Filter { func = extrapolate, degen = blur } // The blur could be exaggerated by downsampling to half size
};我的问题是我搞错了
A field initializer cannot reference the nonstatic field, method or property.我有一种感觉,问题是委托,但我不确定-我从来没有需要移植这类代码之前。
ImagingDefs和V2fT2f都不被声明为静态
被调用的方法通常是
public void foo(ImagingDefs.V2fT2f[]quad, float t)没有任何地方是静态的。
名称V2fT2f来自原始源代码
发布于 2014-08-11 18:01:57
字段初始化器不能引用非静态字段、方法或属性。指的是过滤器方法,如brightness。
如果要在字段初始化器filter中引用这些方法,它们必须是静态的。
另一个选项是在要定义的类的构造函数中初始化该字段。
例如。
public class MyNewClass
{
public delegate void procfunc(ImagingDefs.V2fT2f[] quad,float t);
public class Filter
{
public procfunc func;
public procfunc degen;
};
public Filter[] filter;
public MyNewClass()
{
filter = new Filter[]
{
new Filter { func = brightness },
new Filter { func = contrast },
new Filter { func = extrapolate, degen = greyscale },
new Filter { func = hue },
new Filter { func = extrapolate, degen = blur } // The blur could be exaggerated by downsampling to half size
};
}
}https://stackoverflow.com/questions/25249403
复制相似问题