This question already has an answer here:
这个问题已经有了答案:
- What does the term “opaque type” mean in the context of “CFBundleRef opaque type”? 3 answers
- “不透明类型”这一术语在“CFBundleRef不透明类型”的语境中是什么意思?3答案
"Class" is said to be the opaque type of a class. What does it mean? Is it the type of a class?
“类”是类的不透明类型。这是什么意思?它是类的类型吗?
One more thing, are classes pointers to structs or basically structs?
还有一件事,类指向结构的指针还是结构?
1 个解决方案
#1
0
A variable of Class
type can hold a pointer to a class object, just like a variable of id
type can hold a pointer to any object. A class object is an object. If you have a variable of type id
, you don't know what kind of thing is in it; the same with Class
. You just know that it's an object. I don't know where you got this "opaque type" term from.
类类型的变量可以持有指向类对象的指针,就像id类型的变量可以持有指向任何对象的指针一样。类对象是对象。如果你有一个id类型的变量,你不知道里面有什么东西;相同的类。你只知道它是一个物体。我不知道你从哪里得到这个"不透明"的术语。
You can say that objects are structs, since they consist of a bunch of things laid out together in a certain way in memory. But you should never care about the internal structure of objects. That's an implementation detail of the runtime. The structs you see in the Apple runtime headers, like objc_object
, objc_class
, etc. are not exactly what the object is -- they represent the structure of the "beginning" of an object in the Apple runtime; but objects contain more stuff beyond what those structs describe, like its instance variables.
你可以说,对象是struct,因为它们是由一堆以某种方式在内存中排列的东西组成的。但你不应该关心物体的内部结构。这是运行时的实现细节。在Apple runtime header中看到的结构,如objc_object, objc_class,等等并不完全是对象的结构——它们代表了苹果运行时中对象的“开始”的结构;但是对象包含的东西比那些结构描述的要多,比如它的实例变量。
#1
0
A variable of Class
type can hold a pointer to a class object, just like a variable of id
type can hold a pointer to any object. A class object is an object. If you have a variable of type id
, you don't know what kind of thing is in it; the same with Class
. You just know that it's an object. I don't know where you got this "opaque type" term from.
类类型的变量可以持有指向类对象的指针,就像id类型的变量可以持有指向任何对象的指针一样。类对象是对象。如果你有一个id类型的变量,你不知道里面有什么东西;相同的类。你只知道它是一个物体。我不知道你从哪里得到这个"不透明"的术语。
You can say that objects are structs, since they consist of a bunch of things laid out together in a certain way in memory. But you should never care about the internal structure of objects. That's an implementation detail of the runtime. The structs you see in the Apple runtime headers, like objc_object
, objc_class
, etc. are not exactly what the object is -- they represent the structure of the "beginning" of an object in the Apple runtime; but objects contain more stuff beyond what those structs describe, like its instance variables.
你可以说,对象是struct,因为它们是由一堆以某种方式在内存中排列的东西组成的。但你不应该关心物体的内部结构。这是运行时的实现细节。在Apple runtime header中看到的结构,如objc_object, objc_class,等等并不完全是对象的结构——它们代表了苹果运行时中对象的“开始”的结构;但是对象包含的东西比那些结构描述的要多,比如它的实例变量。