gpt4 book ai didi

objective-c - Objective-C 中的结构继承?

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:05 26 4
gpt4 key购买 nike

在Objective-C中有类似struct继承的东西吗?

例如,C++ 允许我做类似的事情:

struct animal {
int weight;
string name;
}

struct dog : animal {
string breed;
}

struct cat : animal {
bool playsWithLaserPointer;
}

有没有什么方法可以在 Objective-C 中做同样的事情而不求助于 Objective-C++?

最佳答案

结构中的结构工作:

struct animal {
int weight;
char *name;
};

struct dog {
struct animal base;
char *breed;
};

struct cat {
struct animal base;
bool playsWithLaserPointer;
};

Apple 在带有 CGPoint 和 CGSize 的 CGRect 中使用它

关于objective-c - Objective-C 中的结构继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22726887/

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