我正在尝试采用 C 风格的向量并将其转换为 NSMutable 数组对象。
这是功能:
+(NSMutableArray*)arrayFromPoints:(vector<Point2f>&)points
{
    NSMutableArray* pointArray = [[NSMutableArray alloc] init];
    for (int i=0;i<points.size();i++)
    {
        Point2f point = points[i];
        JBPoint* point2 = [[JBPoint alloc]initWithX:point.x andY:point.y];
        [pointArray addObject:point2];
    }
    return pointArray;
}
自定义点类:
 @implementation JBPoint
float _x;
float _y;
-(id) initWithX:(float)x andY:(float)y
{
    if (self=[super init])
    {
       _x = x;
       _y=y;
    }
    return self;
}
-(float)x{ return _x;}
-(float)y {return _y;}
@end
测试输出:
for (JBPoint* pnt in array)
{
    NSLog(@"%f, %f", pnt.x, pnt.y);
}
我除了它来输出数组,但每次它只给我最后一个值!有谁知道为什么?
我认为它们可能指向同一个对象,但它们具有不同的内存地址。