2011-11-23 55 views
-3

我想从目标c翻译到C++。但是有一些客观的c sintax对我不明确。帮我PLZ明白这是什么:initWithName在目标c

@synthesize contrast = _contrast; 

我觉得这产生的getter setter方法属性命名对比度 但什么是_contrast?我还没有发现它在任何地方项目除了一个地方(下同)

然后在另一个功能:

_firstParameter = [ [ MPPostProcessParameter alloc ] initWithName: @"Contrast" minValue: 0.4f maxValue: 2.0f defaultValue: 1.0f ]; 

确定。这里我想我们初始化这个属性名为contrast(见上面),它包含MPPostProcessParameter的构造函数(minValue:0.4f maxValue:等等) 但是! 在其他函数中这个对比属性用作float!不是MPPostProcessParameter类型的对象!

function (xxx, _contrast); //? the second argument must be float! 

帮助我PLZ了解什么是

_firstParameter = [ [ MPPostProcessParameter alloc ] initWithName: @"Contrast" minValue: 0.4f maxValue: 2.0f defaultValue: 1.0f ]; 

在C++语言编写(什么是initWithName什么这个功能做的话) 谢谢

+0

我认为'_firstParameter'的问题不是因为MPPostProcessParameter对象没有存储在_contrast变量中(正如你的问题所暗示的),而是存储在_firstParameter中。你确定所有的片段都是正确的吗? –

回答

0

关于第一个问题:该声明确实为属性contrast生成了getter/setter方法。我在difference between session and _session (facebook integration)_contrast中描述了它的一些,这里是为这个属性创建的(内部)实例变量的名称。虽然你可以自己在类声明中声明实例变量,但你不需要。如果以这种方式使用synthesize语句,编译器将为您生成一个实例变量。另外,如果你只是使用@synthesize contrast;而没有指定实例变量名称,那么实例变量将与属性(和getter方法)具有相同的名称,这在目标C中是没有问题的。

+0

谢谢你的回答 – curiousity