gpt4 book ai didi

Objective-C 如何返回结构数据类型?

转载 作者:搜寻专家 更新时间:2023-10-30 19:50:51 25 4
gpt4 key购买 nike

struct Line {

NSUInteger x1;
NSUInteger x2;
};

// ...

- (Line)visibleLine;

上面的代码显然不起作用,因为 Line 不是有效类型。有什么建议吗?

最佳答案

Objective-C 是基于 C 而不是 C++。在 C 中我们需要使用 struct Line,而在 C++ 中 Line 就可以了。

你可以这样做:

struct {
NSUInteger x1;
NSUInteger x2;
} Line;

// ...

- (struct Line)visibleLine{

}

struct Line {
NSUInteger x1;
NSUInteger x2;
};
typedef struct Line Line;

// ...

- (Line)visibleLine;

Above is preferred by most C frameworks.

此外,

typedef struct {
NSUInteger x1;
NSUInteger x2;
} Line;

// ...

- (Line)visibleLine;

关于Objective-C 如何返回结构数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15406086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com