美文网首页八天学会OC
第01天OC语言(14):常见错误

第01天OC语言(14):常见错误

作者: liyuhong | 来源:发表于2017-07-20 14:08 被阅读14次
一、概念
/*
 错误
    1.只有类的声明,没有类的实现 
    2.漏了@end
    3. @interface 和 implementtation嵌套
    4.成员变量 没写在括号里面
    5.方法的声明 写在了 大括号里面
    6.成员变量 不能在{}中进行初始化, 不能被直接拿出去访问
    7. 方法不能当做函数一样调用
    8.OC方法只能声明 @interface 和 end之间, 只要将实例在@implementation, 和 gend之间, 也就是说 OC方法不能独立于类 存储
    9.C语言不属于类, 跟类没有联系, C语言只归定义函数的文件所有
    10. C函数 不能访问OC对象的成员
    11. 低级错误 :  方法有声明, 但是实现的时候 写成了函数
    12. OC可以没有 @interface 一样可以定义一个类
 */
二、代码
#import <Foundation/Foundation.h>
#pragma mark 类
@interface Person : NSObject
{
    static  int _age; // Type name does not allow storage to be specified
}
- (void)test;
@end
@implementation Person
//-(void)test
//{
//    NSLog(@"test");
//}

void test()
{
    printf("test");
}
@end




#pragma mark main函数
int main(int argc, const char * argv[])
{
    Person *p = [Person new];
    [p test];
    return 0;
}
image.png image.png image.png

相关文章

网友评论

    本文标题:第01天OC语言(14):常见错误

    本文链接:https://www.haomeiwen.com/subject/wlcphxtx.html