gpt4 book ai didi

objective-c - 使用 NSArray 作为参数声明函数

转载 作者:行者123 更新时间:2023-11-28 23:11:26 38 4
gpt4 key购买 nike

我有一个函数如下:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount
{

// Do some stuff

return foo;
}

我在头文件中这样声明:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount;

但是当我尝试使用同一文件中别处返回的 int 值时,出现错误“函数的隐式声明在 c99 中无效”。我没有正确声明函数吗?

更新

我意识到我没有以标准化的方式声明这一点,我根据 MarkGranoff 的建议更改了我的声明(请参阅上面的更改),但这次我仍然收到它作为警告。

这里是我如何调用这个函数的上下文:

-(int)fooTotal: (int)amount 
{

int totalFee = 0;

// Declare arguments
NSArray *percentages = [[NSArray alloc] initWithObjects:firstValue, secondValue, thirdValue, fourthValue, fifthValue, nil];
NSArray *amounts = [[NSArray alloc] initWithObjects:sixthValue, seventhValue, eigthValue, ninthValue, nil];

totalFee = ladderCalc(amounts,percentages,amount);

return totalFee;
}

因此,尽管就 Obj-C 风格而言这似乎是有意义的,但我仍然收到警告。

我很确定我没有正确调用这个函数,我在编译项目时遇到无法识别的符号错误。

Undefined symbols for architecture i386:
"_ladderCalc", referenced from:
-[FeeCalcLibrary getMFModelTotal:] in FeeCalcLibrary-A83D2A7637F57664.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

试试这个:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount;

并更改实现的签名以匹配。然后你有参数名称,你可以在方法的代码中引用。即:金额、百分比和金额。

关于objective-c - 使用 NSArray 作为参数声明函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8159236/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com