Привет Я пытаюсь изучить концепцию Opps в Objective C, но я знаю PHP, поэтому я взял программу, в которой для публичной, частной и защищенной упомянутой ниже.public private и protected in object-c
<?php
//Public properties and method can be inherited and can be accessed outside the class.
//private properties and method can not be inherited and can not be accessed outside the class.
//protected properties and method can be inherited but can not be accessed outside the class.
class one
{
var $a=20;
private $b=30;
protected $c=40;
}
class two extends one
{
function disp()
{
print $this->c;
echo "<br>";
}
}
$obj2=new two;
$obj2->disp(); //Inheritance
echo"<br>";
$obj1=new one;
print $obj1->c; //Outside the class
?>
Так что я пытаюсь преобразовать в Objective c code, упомянутый ниже.
#import <Foundation/Foundation.h>
@interface one : NSObject
{
@private int a;
@public int b;
@protected int c;
}
@property int a;
@property int b;
@property int c;
@end
@implementation one
@synthesize a,b,c;
int a=10;
int b=20;
int c=30;
@end
@interface two : one
-(void)setlocation;
@end
@implementation two
-(void)setlocation;
{
// NSLog(@"%d",a);
NSLog(@"%d",b);
// NSLog(@"%d",c);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
two *newtwo;
newtwo =[[two alloc]init];
//calling function
[newtwo setlocation];
}
return 0;
}
Когда я запускаю приведенный выше код я получаю
2015-11-03 23:20:16.877 Access Specifier[3562:303] 0
Может кто-нибудь решить мою проблему.
Вы компилируете это для iOS или OS X? –
Я компилирую это в инструменте командной строки OS X. Просто хочу знать о публичной частной и защищенной концепции. – VyTcdc