object c 中的 self 含義

2021-08-26 04:55:31 字數 735 閱讀 8816

self就是當前例項的指標。

所以 看這個例子:

superclass

subclass : superclass

#import @inte***ce superclass : nsobject 

- (void) printself;

@end

@implementation superclass

- (void) printself

subclass 中的**中的

@implementation subclass

- (void) printself

那麼當subclass* subc = [[subclass

alloc] init];

[subc printself];

結果會輸出什麼呢?

2011-09-17 17:38:55.829 testselfclass[755:903] subclass

2011-09-17 17:38:55.830 testselfclass[755:903] subclass

是的是 subclass 並沒有 superclass.

這個特性有助於我們寫copy函式,分配記憶體的時候分配的是子類的記憶體 而不是 父類的記憶體。

Python中的self的含義!

class test def prt self print self print self.class t test t.prt main test object at 0x000001ade41b1710 self代表的是類的例項。而self.class 則指向類。t main test obje...

Python中self的含義 進製轉換

1 一篇文章讓你徹底搞清楚python中self的含義 python中self用法詳解 python中self的含義 python self引數 函式詳解 2 python中0.3怎麼轉二進位制 python hex 函式 轉換為二進位制函式 bin 轉換為八進位制函式 oct 轉換為十進位制函式 ...

Python 理解類中self的含義

self代表的是類的例項,而不是類 class test object def prt self print self print self.class t test t.prt 執行結果 main test object at 0x10fe90fd0 從上面的執行結果可以看出,self指向是類的例...