从函数返回CGPoints

时间:2012-02-18 15:51:30

标签: cgpoint

我还有一个关于在{:: 1>}中传递CGPoint的问题。

(CGPoint[]) displayPoints:(CGPoint) startPoint 
                        withEnd:(CGPoint) endPoint
                 withBaseRotate:(Boolean) baseRotate {

// do some stuf with four or six points
// create a array of the points and return - it


    CGPoint ourPoints[] = {
        CGPointMake(point1.x, point1.y),
        CGPointMake(point2.x, point2.y),
        CGPointMake(point3.x, point3.y),
        //... some more points
    } ;

  return ourPoints[];
}

为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

必须返回一个指针,指向存储在内存中的位置

(const CGPoint *) displayPoints:(CGPoint) startPoint 
                  withEnd:(CGPoint) endPoint
           withBaseRotate:(Boolean) baseRotate {

    CGPoint ourPoints[] = {
        CGPointMake(point1.x, point1.y),
        CGPointMake(point2.x, point2.y),
        CGPointMake(point3.x, point3.y),
        //... some more points
    } ;

  return ourPoints;
}

如果你看一下CFContextAddLines的签名,你会发现他们正在使用它。现在编译器会抛出一个警告,返回一个指向内存的指针......所以我不确定这是否是首选方式,但它会回答你的问题。