2012-02-18 33 views
0

返回CGPoints我對自己在路口通過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[]; 
} 

這是爲什麼不工作?

回答

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的簽名,你會看到這是他們正在使用的。現在編譯器會發出一個警告,告訴它返回一個指向內存的指針......所以我不確定這是否是首選方式,但它回答了你的問題。