2015-10-31 21 views
1

我是IOS編程中的新手。我已經在C++中學習到,'this pointer'被使用並且只能在內部訪問,並且只能用於實例函數(對象方法與在IOS中一樣)。我們可以在類函數(IOS中的類方法)內'訪問''這個指針''。但我已經檢查過,我也可以在IOS中的類方法內使用它們(作爲自己)。但我不知道,可能是我的觀念錯誤或不對。我搜查了很多網站。我已經檢查過,很多地方都使用過它。如果'自我'可以在課堂上使用,那麼任何人都可以告訴我,怎麼可能?是「自我」的概念是在C「這個指針」 ++不同。請解釋它預先使用自我keyin目標C

#import" ViewController.h" 

@implementation ViewController 

+(void)fun 

{ 
    [self action]; //here you can see ,Iam using 'self' for access method action.           

}// but according to C++ this pointer (self)can't be used in class method. 

    // not giving any error...please check. 


+(void)action 
{ 

NSLog(@" Welcome in IOs world"); 

} 

-(void)viewDidLoad{ 
    [superviewDidLoad]; 

ViewController*obj=[[ViewController alloc]init]; 

    [ViewController fun]; 

} 

@end 
+0

你應該調用[obj fun]而不是[viewcontroller fun] –

回答

0

一步step..Thanks在一類方法self指類,並且在一個實例方法self指的是類的實例。因此可以使用相同的術語,但在不同範圍內意味着不同的事物。