2010-07-06 63 views
2

我有一个方法:我在这里做了什么愚蠢的noob错误?

- (CGPoint) calculateVectorBetweenThisPoint:(CGPoint)firstPoint andThisPoint:(CGPoint)secondPoint 
{ 
    float xDif = firstPoint.x - secondPoint.x; 
    float yDif = firstPoint.y - secondPoint.y; 

    return CGPointMake(xDif, yDif); 
} 

我尝试如下调用它:

- (float) angleBetweenThisPoint:(CGPoint)firstPoint andThisPoint:(CGPoint)secondPoint 
{ 
// COMPILE ERROR HERE: Invalid Initializer 
    CGPoint vector = [self calculateVectorBetweenThisPoint:firstPoint andThisPoint:secondPoint]; 

    return atan2(vector.x, vector.y); 
} 

但我得到一个编译erorr,我尝试使用方法:“无效的初始化程序”。

我在做什么错?

回答

5

calculateVectorBetweenThisPoint:andThisPoint:是否在使用前声明?如果不是,编译器将假定返回类型为id,这对于放入CGPoint绝对是无效的。

+0

正确。 'calculateVectorBetweenThisPoint:andThisPoint:'必须在头文件中定义,或者放置在实现文件中的'angleBetweenThisPoint:andThisPoint:'之前。 – 2010-07-06 11:24:01

+0

+1(即使你的意思是声明,没有定义) – 2010-07-06 11:38:10

+0

哎呀,你是对的。编辑! – Wevah 2010-07-06 11:41:57