术语“不透明类型”是什么?表示“CFBundleRef opaque type”的上下文? [英] What does the term "opaque type" mean in the context of "CFBundleRef opaque type"?

查看:133
本文介绍了术语“不透明类型”是什么?表示“CFBundleRef opaque type”的上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人对不透明类型有什么好的解释吗?我在 CFBundleRef 的上下文中看到了这个术语,他们在这里说:CFBundleRef opaque type。这是一种只读的类型吗?

Does someone have a good explanation of what an "opaque type" is? I saw that term in context of the CFBundleRef, where they were saying: "CFBundleRef opaque type". Is that a type that's readonly?

推荐答案

opaque类型是一种你没有完整定义的类型 struct class 。在C,C ++和Objective-C中,您可以告诉编译器稍后将使用前向声明定义类型:

An "opaque type" is a type where you don't have a full definition for the struct or class. In C, C++ and Objective-C, you can tell the compiler that a type will be defined later by using a forward declaration:

// forward declaration of struct in C, C++ and Objective-C
struct Foo;

// forward declaration of class in C++:
class Bar;

// forward declaration of class in Objective-C:
@class Baz;

编译器没有足够的信息让你直接用 struct 或 class 除了声明它的指针,但这通常是你需要做的。这允许库和框架创建者隐藏实现细节。然后,库或框架的用户调用辅助函数来创建,操作和销毁前向声明的 struct 类的实例 。例如,框架创建者可以为 struct Foo 创建这些函数:

The compiler doesn't have enough information to let you do anything directly with the struct or class except declare pointers to it, but this is frequently all you need to do. This allows library and framework creators to hide implementation details. Users of a library or framework then call helper functions to create, manipulate and destroy instances of a forward declared struct or class. For example, a framework creator could create these functions for struct Foo:

struct Foo *createFoo(void);
void addNumberToFoo(struct Foo *foo, int number);
void destroyFoo(struct Foo *foo);

作为Core Foundation框架的一部分,Apple制作了常见的Objective-C类,如 NSString NSArray NSBundle 可供C程序员通过opaque类型使用。 C程序员使用指针和辅助函数来创建,操作和销毁这些Objective-C类的实例。 Apple称之为免费桥接。它们遵循一个共同的命名约定:CF前缀+类名+Ref后缀,其中CF代表Core Foundation,Ref代表Reference,意思是指针。

As part of the Core Foundation framework, Apple makes common Objective-C classes like NSString, NSArray and NSBundle available to C programmers through opaque types. C programmers use pointers and helper functions to create, manipulate and destroy instances of these Objective-C classes. Apple calls this "toll-free bridging". They follow a common naming convention: "CF" prefix + class name + "Ref" suffix, where "CF" stands for "Core Foundation" and "Ref" is short for "Reference", meaning it's a pointer.

这篇关于术语“不透明类型”是什么?表示“CFBundleRef opaque type”的上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆