0
嗨夥計,這是jagadeesh,一邊練習應用程序,參照該平臺的IM初學者一些書,我的應用程序運行Suceessfully但在控制檯無輸出顯示這裏是我的申請#進口關於在Xcode調試
@interface ClassA : NSObject
{
int x;
}
-(void) initVar;
@end
@implementation ClassA
-(void) initVar
{
x = 100;
}
@end
@interface ClassB : ClassA
{
int y;
}
-(void) initVar;
-(void) printVar;
@end
@implementation ClassB
-(void) initVar
{
x = 200;
y = 300;
}
- (void) printVar
{
NSLog(@"x= %i", x);
NSLog(@"y= %i", y);
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
ClassB *b = [[ClassB alloc] init];
[b initVar];
[b printVar];
[b release];
[pool drain];
return 0;
}
和****控制檯信息是這樣的**** 程序加載。 運行 [切換處理1310本地線程0x2e03] 運行... (GDB)
在一個不相關的說明中,您應該避免訪問子類的方法(如ClassB的'-initVar')中父類的成員變量(例如'x')。相反,爲設置成員的父代創建init和accessor方法,並調用子進程的方法。使用ObjC 2.0,您可以使用屬性:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html – outis 2009-10-20 09:35:13