简体   繁体   English

如何以与该函数相同的方式获取这些参数?

[英]How to take these parameters the same way this function does?

For example: 例如:

- (BOOL)compare:(NSDecimal)leftOperand greaterThan:(NSDecimal)rightOperand {
    NSComparisonResult result = NSDecimalCompare(&leftOperand, &rightOperand);
    // rest not important
}

like you can see, the method just receives these two types of NSDecimal, leftOperand and rightOperand. 如您所见,该方法仅接收NSDecimal的这两种类型,leftOperand和rightOperand。 Then it passes them on to a C API function which likes to have them by reference. 然后将它们传递给C API函数,该函数喜欢通过引用获得它们。 Sorry if that's the wrong term, didn't study that stuff. 抱歉,如果这是一个错误的词,请不要学习这些东西。 Currect me if I'm wrong :-) 如果我错了,请纠正我:-)

I want to modify this method in such a way, that I can also accept parameters the way that function does. 我想以这种方式修改此方法,以便我也可以像函数那样接受参数。 I think that's clever, because the method won't copy the parameters (I believe it does). 我认为这很聪明,因为该方法不会复制参数(我相信会)。 What would I have to add in there in order to get this reference thing right? 我必须在其中添加什么才能正确使用此参考资料? And after that, my parameters are just references, right? 然后,我的参数只是引用,对吧? How would I pass these then along to the NSDecimalCompare function? 我如何将这些传递给NSDecimalCompare函数?

I slighlty remember there was some dereferencing operator around for that? 我很高兴地记得周围有一些解引用运算符吗?

Try: 尝试:

- (BOOL)compare:(const NSDecimal*)leftOperand greaterThan:(const NSDecimal*)rightOperand {
    NSComparisonResult result = NSDecimalCompare(leftOperand, rightOperand);
    // rest not important
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLHANDLE-Parameters:函数不带x个参数(但实际上有) - SQLHANDLE-Parameters: function does not take x arguments (but it does, actually) 如何在函数参数中通过引用获取数组? - How to take arrays by reference in function parameters? 是否有人拥有书面证据来确保函数中参数的定义方式与普通变量声明相同? - Does anyone have the written evidence which assure that the way parameters are defined in a function is the same as normal variable declarations? 如何定义一个 function,其参数从 main() function 获取变量? - How to define a function, parameters of which take variables from main() function? 有没有办法使C ++函数采用具有相同成员的两种不同类型? - Is there a way for a C++ function to take two different types with same members? ios :: setstate实际上需要多少个参数? - How many parameters does ios::setstate actually take? 函数不接受 0 个参数 - Function does not take 0 Arguments 函数不带1个参数 - function does not take 1 arguments 为什么要将对象的副本作为函数的参数? 为什么 const ref 不是参数的默认方式? - Why would you ever take the copy of an object as a parameter to your function? Why are not const ref the default way of parameters? 如何将具有不同参数的std :: function传递给同一个函数 - How to pass std::function with different parameters to same function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM