按同一类的方法使用类方法时发生Xcode错误

按同一类的方法使用类方法时发生Xcode错误,xcode,pointers,casting,xcode4.2,class-method,Xcode,Pointers,Casting,Xcode4.2,Class Method,我有一个类,它的类方法是“getSimulatedPricesFrom”。在执行过程中,它将从同一个类调用方法“projectFromPrice”。但是在sTPlus1行中,我遇到了两个错误: 1) Class method "projectFromPrice" not found 2) Pointer cannot be cast to type "double" 有人知道为什么吗?我已经在.h文件中声明了该方法 以下是AmericanOption.m文件中的部分编码: #import

我有一个类,它的类方法是“getSimulatedPricesFrom”。在执行过程中,它将从同一个类调用方法“projectFromPrice”。但是在sTPlus1行中,我遇到了两个错误:

1) Class method "projectFromPrice" not found

2) Pointer cannot be cast to type "double" 
有人知道为什么吗?我已经在.h文件中声明了该方法 以下是AmericanOption.m文件中的部分编码:

#import "AmericanOption.h"

@implementation AmericanOption

+(NSMutableArray*)getSimulatedPricesFrom:(double)s0 withRate:(double)r0 withVol:(double)v0 withDays:(int)D withPaths:(int)N
{
    double daysPerYr = 365.0;
    double sT;
    double sTPlus1;
    sT = s0;
...
    sTPlus1 = (double)[AmericanOption projectFromPrice:sT, r0/daysPerYr, v0/daysPerYr, 1/daysPerYr];
...
    return arrPricePaths;
}

+(double)projectFromPrice:(double)s0 withRate:(double)r0 withVol:(double)v0 withDt:(double)dt
{
    ...
}

看起来您应该按如下方式调用projectFromPrice方法:

sTPlus1 = [AmericanOption projectFromPrice:sT 
                                  withRate:r0/daysPerYr 
                                   withVol:v0/daysPerYr 
                                    withDt:1/daysPerYr];
在示例代码中,您只是提供了一个以逗号分隔的参数列表。您应该使用该方法的命名参数

两个错误中的第一个错误是因为方法
projectFromPrice:
与方法
projectFromPrice:withRate:withVol:withDt:
不同

projectFromPrice:withRate:withVol:withDt:
是实际存在的方法,可能是在接口(.h文件)中定义的
projectFromPrice:
是您试图调用但不存在的方法


第二个错误是由于编译器假设未定义的
projectFromPrice:
方法返回一个
id
(指针),该id不能转换为双精度。

这是调用第二个方法的方式,似乎是问题所在。请尝试以下方法:

+(NSMutableArray*)getSimulatedPricesFrom:(double)s0 withRate:(double)r0 withVol:(double)v0 withDays:(int)D withPaths:(int)N
{
    double daysPerYr = 365.0;
    double sT;
    double sTPlus1;
    sT = s0;
...
    sTPlus1 = (double)[AmericanOption projectFromPrice:sT withRate:r0/daysPerYr withVol:v0/daysPerYr withDt:1/daysPerYr];
...
    return arrPricePaths;
}

+(double)projectFromPrice:(double)s0 withRate:(double)r0 withVol:(double)v0 withDt:(double)dt
{
    ...
}