2012-04-24 5 views
0

클래스 메서드 "getSimulatedPricesFrom"이 있습니다. 실행 중에 동일한 클래스에서 "projectFromPrice"메서드를 호출합니다. 그러나 라인 sTPlus1 라인에서 나는 2 개의 오류가 발생합니다 :동일한 클래스의 메서드로 클래스 메서드를 사용하는 중 Xcode 오류가 발생했습니다.

1) Class method "projectFromPrice" not found 

2) Pointer cannot be cast to type "double" 

아무도 이유에 대해 알고 있습니까? 난 이미 다음 AmericanOption.m 파일의 코드의 일부입니다 .H 파일 의 방법을 선언 한 :

sTPlus1 = [AmericanOption projectFromPrice:sT 
            withRate:r0/daysPerYr 
            withVol:v0/daysPerYr 
            withDt:1/daysPerYr]; 

에서 다음과 같이 당신이 projectFromPrice 메서드를 호출해야합니다 같은

#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:projectFromPrice:withRate:withVol:withDt:과 같지 않기 때문에 첫 번째 오류가 발생합니다.

projectFromPrice:withRate:withVol:withDt: 실제로 존재하며 아마도 인터페이스 (.h 파일)에 정의 된 방법입니다. projectFromPrice:은 호출하려고 시도했지만 존재하지 않는 메소드입니다.

두 번째 오류는 컴파일러에서 정의되지 않은 projectFromPrice: 메서드가 double로 캐스팅 할 수없는 id (포인터)을 반환한다고 가정 한 결과입니다.

+0

O..ic ... 감사합니다. 이제 작동합니다! –

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 
{ 
    ... 
} 
관련 문제