【发布时间】:2011-04-20 00:37:09
【问题描述】:
在 Leopard 10.5.8 下使用 GCC 4 在 XCode 3.1.3 中编译,我的目标是 10.5...
我有一个接口,因此:
@interface testThing : NSObject { classContaininghooHa *ttv; }
@end
还有一个实现,因此:
@implementation: testThing
- (void) instanceMethodMine
{
[ttv hooHa]; // works perfectly, compiles, links, hooHa is invoked.
}
// void cFunctionMine()
// {
// [ttv hooHa]; // compiler: 'ttv' undeclared (first use in this function) "
// }
void stupidCFunctionMine((testThing *)whom) // whom is passed class 'self' when invoked
{
[whom instanceMethodMine]; // compiles, links, works. :/
}
@end
现在,我的理解——显然是有缺陷的——是如果你声明了一个变量、类 ID 或其他,它是类私有的,但在类中,本质上是作为全局执行的,存储在分配的类中实例在其存在期间。
这就是它对 objc 方法的作用。
但是在上面的 c 函数中,也写在类中,变量似乎是不可见的。对我来说没有意义,但确实如此。
谁能给我解释一下这是怎么回事?
当您使用它时,如何将其声明为实例变量,以便我可以在如上所示的类范围内声明的 c 函数内以及在方法内使用该方法?
非常感谢您的洞察力。
【问题讨论】:
标签: objective-c cocoa macos