2012-04-24 19 views
0

我有一個類的類方法「getSimulatedPricesFrom」。它將在執行過程中從同一個類中調用方法「projectFromPrice」。然而,在行sTPlus1線,我遇到了2個錯誤:使用類方法通過相同類的方法的Xcode錯誤

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 
{ 
    ... 
} 

回答

1

看起來你應該調用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:方法返回無法轉換爲double的id(指針)的結果。

+0

O..ic ...謝謝。它現在有效! – 2012-04-25 12:38:05

0

這就是你稱呼你的第二種方法似乎是問題的方式。試試這個,而不是:

+(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 
{ 
    ... 
} 
相關問題